• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    获取DataList控件的主键和索引实用图解
    “哈哈,看了这篇https://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);
    }
    }
    }
    您可能感兴趣的文章:
    • 通过RadioButton对DataList控件进行单选实例说明
    • 动态加载用户控件至DataList并为用户控件赋值实例演示
    • Datalist控件使用存储过程来分页实现代码
    • asp.net datalist 用法
    • DataList中TextBox onfocus调用后台void静态方法及获取相应行数
    上一篇:gridview checkbox从服务器端和客户端两个方面实现全选和反选
    下一篇:ASP.NET中的URL过滤实现代码
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    获取DataList控件的主键和索引实用图解 获取,DataList,控件,的,主键,