我在用户控件中有一个gridview,并使用占位符动态添加了控件现在我从网格中找到控件,它给出的控件在网格中不存在代码如下:
foreach (GridViewRow row in GridView1.Rows)
{
PlaceHolder plc = (PlaceHolder)row.FindControl("lblPlaceHolder");
TextBox txtTextBox1 = plc.FindControl("txtTextBox1") as TextBox; //its give Null
}
谁能回答lz
从评论中添加代码:
foreach (GridViewRow dr in GridView1.Rows)
{ PlaceHolder placeHolder = dr.FindControl("lblPlaceHolder") as PlaceHolder;
TextBox txtTextBox1= new TextBox();
txtTextBox1.Width = 300;
placeHolder.Controls.Add(txtTextBox1);
}