Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在gridview中查找控件?在Asp.net中?_Asp.net - Fatal编程技术网

在gridview中查找控件?在Asp.net中?

在gridview中查找控件?在Asp.net中?,asp.net,Asp.net,在web应用程序中,我试图在RowDataBound事件中查找网格控件。但它给对象引用一个对象的实例,这是我的代码: protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e) { string empid = ""; empid = ((Label)e.Row .FindControl("

在web应用程序中,我试图在RowDataBound事件中查找网格控件。但它给对象引用一个对象的实例,这是我的代码:

     protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e)
          {

                 string empid = "";         

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

请帮我查找控件,谢谢。

仅查找数据行的控件,如:

protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e)
{

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

           empid = ((Label)e.Row .FindControl("lblname")).Text;
       }
 }
“对象引用到对象实例”错误可能是因为未为当前行找到名为lblname的控件


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

Ya,我得到了答案,我必须放置

        string empid = "";
        if (e.Row.RowType == DataControlRowType.DataRow)  
        {
            empid = ((Label)e.Row.FindControl("lblname")).Text;
        }

然后我们得到控件

试试这个
标签lblprop\u img\u id=(Label)e.Row.Cells[2].FindControl(“lblprop\u img\u id”)  Label lbl = (Label)e.Row.Cells[2].FindControl("lblCreatedBy");
             lbl.Text = "ABC";