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