首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在RowDataBound中获取SelectedDataKey

在RowDataBound中获取SelectedDataKey
EN

Stack Overflow用户
提问于 2012-01-04 02:52:27
回答 1查看 589关注 0票数 0

由于尚未选择SelectedDataKey,因此此代码将返回NullReferenceException。如何检查DataKey是否已选中。

代码语言:javascript
复制
    protected void grdRoles_RowDataBound1(object sender, GridViewRowEventArgs e) 
    {
       if (e.Row.RowType == DataControlRowType.DataRow) 
       { 
          CheckBox chk = (CheckBox)e.Row.FindControl("chkRole"); 
          int rolecode = Convert.ToInt32(this.grdRoles.DataKeys[e.Row.RowIndex].Value);
          BusinessLayer.Customers checkRole = new BusinessLayer.Customers();                   

         bool check = checkRole.CheckRoles(this.grdCustomers.SelectedDataKey.Value.ToString(), rolecode); //this is triggering the nullReferenceException
         if (check)
         {
           chk.Checked = true;
         }                   
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 03:03:25

您将需要使用不同的事件。数据绑定事件用于将数据连接到视图。您正在寻找一个事件,以便在绑定数据后使用该数据。很可能是SelectedIndexChangingSelectedIndexChanged事件

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8717175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档