2012-01-12 69 views
1

在web应用程序中,我试图在RowDataBound事件中查找网格控件。但它提供对象的实例的对象参考,这是我的代码:在gridview中查找控件?在Asp.net中?

 protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e) 
      { 

       string empid = "";   

       empid = ((Label)e.Row .FindControl("lblname")).Text; 
      } 

您可以传唤我找到控件,谢谢。

+0

试试这个'标签lblprop_img_id =(标签)e.Row.Cells [2 ] .FindControl(“lblprop_img_id”);' – Murtaza 2012-01-12 09:36:41

回答

1

雅,我得到了答案,我必须把

​​

然后我我们得到了控制

1

的数据行只喜欢寻找控制:

protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 

    if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      string empid = "";   

      empid = ((Label)e.Row .FindControl("lblname")).Text; 
     } 
} 
+0

ya谢谢你,pankaj,我明白了,我发布了我的答案,谢谢你的回复 – 2012-01-12 09:39:48

1

“对象引用对象的实例”,因为没有名为lblname控制被发现的当前行错误可能是。

也许你需要检查行的类型,e.Row.RowType = DataControlRowType.DataRow,这样你就不会在标题行中搜索控件。

1
Label lbl = (Label)e.Row.Cells[2].FindControl("lblCreatedBy"); 
      lbl.Text = "ABC";