全国统一热线:
028-86758058
18980748058
购买流程
付款方式
常见问题
在线提问
续租服务
购物车(
0
件)
用户名:
密 码:
记住
首 页
HOME
域名注册
DOMAIN
虚拟主机
WEB HOST
成品网站超市
AUTO Site
VPS主机
VPS SERVER
云 主 机
CLOUD HOST
租用托管
SERVER
海外主机
HK HOST
代理专区
AGENT
客服中心
SERVICE
站长教程
SERVICE
欢迎光临西部数据云计算中心,我们将竭诚为您提供最优质的服务!
中文域名
域名转入
域名转出
DNS管理
动态域名
获取域名证书
域名停放
域名过户
集群主机
双线主机
基本主机
港台主机
论坛主机
Linux主机
Vip合租主机
超G型主机
ASP.net主机
Java主机
智能建站主机
网店主机
美国主机
数据库
成品网站超市
智能建站主机
集群VPS主机
国内VPS主机
香港VPS主机
美国VPS主机
云主机介绍
云主机购买
服务器租用
主机托管
常见问题
香港主机
港台主机
美国主机
国内免备案
步骤流程
代理级别
代理合同
代理模式
代理优势
在线申请
产品列表
常见问题
代理商分布图
常见问题
有问必答
跟踪提问
购买流程
产品价格
付款方式
常用软件
网站备案
续租服务
汇款确认
相关文档
联系我们
域名资讯
主机资讯
行业动态
网页制作
php教程
mysql教程
域名资讯
云计算资讯
网络编程
您当前的位置:
首页
>
网络编程
>
Net教程
获取DataList控件的主键和索引实用图解
时间:2015-01-29 来源:互联网 作者:佚名
“哈哈,看了这篇http://www.jb51.net/article/33388.htm,只有效果,但没有结果,我怎样获取选择行的相关记录?”
Insus.NET首先多谢网友对上面那篇博文的关注。解决你的问题,可以尝试获取选择行的索引或是主键即可,能获取到主键,其它字段的值,也可以获取到了。
下图中,高亮选择区,即是针对问题解决而在原在代码添加的部分。一是在DataList控件添加一个DataKeyField,以便获取到它的主键值,另外还添加了两个铵钮及一个Label标答,用来显示选择结果,真正将来你也许用不上标签,因为获取到结果之后,就可以进行你想的要事情了。
两个铵钮事件,都是很简单,Insus.NET相信你能看得懂,如果遇上不明,可以讨论:
复制代码
代码如下:
View Code
protected void Button1_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
if (FindControl("DataListConstellation") == null) return;
DataList dlconstellation = (DataList)FindControl("DataListConstellation");
foreach (DataListItem dli in dlconstellation.Items)
{
if (dli.FindControl("RadioButtonSelect") == null) return;
RadioButton rb = (RadioButton)dli.FindControl("RadioButtonSelect");
if (rb.Checked)
{
LabelSelectedResult.Text = string.Format("你执行铵钮'{0}',选择行的索引是:{1}; 主键值是:{2}", button.Text, dli.ItemIndex.ToString(), dlconstellation.DataKeys[dli.ItemIndex].ToString());
break;
}
else
{
LabelSelectedResult.Text = string.Format("你执行铵钮'{0}',没有选择任何一行。", button.Text);
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
DataList dlconstellation = (DataList)FindControl("DataListConstellation");
for (int i = 0; i < dlconstellation.Items.Count; i++)
{
RadioButton rb = (RadioButton)dlconstellation.Items[i].FindControl("RadioButtonSelect");
if (rb.Checked)
{
LabelSelectedResult.Text = string.Format("你执行铵钮'{0}',选择行的索引是:{1}; 主键值是:{2}", button.Text, i.ToString(), dlconstellation.DataKeys[i].ToString());
break;
}
else
{
LabelSelectedResult.Text = string.Format("你执行铵钮'{0}',没有选择任何一行。", button.Text);
}
}
}
来顶一下
返回首页
推荐资讯
获取DataList控件的主键和索引实用
“哈哈,看了这篇http://www.jb51.net/article/33388.htm,只
使用CustomValidator自定义验证控件
在前网页前端处,我们放置ListBox控件,在数据提交前,检查用
相关文章
使用asp.net的pageDataSource中时索引问题解决方法
NET索引器使用方法实例代码
在RowCommand事件中获取索引值示例代码
Asp.Net、asp实现的搜索引擎网址收录检查程序
Asp.Net中索引器的用法分析
asp网络编程:使用ASP建设私人的搜索引擎
根据来路是否为搜索引擎来决定是否跳出弹窗代码
获取关键词及所属来源搜索引擎名称
PHP记录用户通过搜索引擎进网站的关键词并给出相关结果
php为数据库建立索引
栏目更新
栏目热门
返回首页
关于我们
联系我们
付款方式
价格总览
资讯中心
友情链接
媒体关注
有问必答
投诉建议
网站备案
《中华人民共和国增值电信业务经营许可证》编号:川B2-20080058号
官方网址:
xibushuju.com
西部数据
Copyright © 2002~2015
天府快车
版权所有
电话总机:
028-86758058
(50线) 传真:
028-86758058