日期:2014-05-18  浏览次数:20878 次

看看这个问题,关于查找控件的问题
Label lbLong = new Label(); lbLong.ID="lbLong" lbLong.Text = "asdfagsdfg"
e.Row.Cells[2].Controls.Add(lbLong);

这是在绑定GridView时向GridView里添加的控件
为什么用
Response.Write(gdView.Rows[i].Cells[1].Controls.Count);
和gdView.Rows[i].Cells[1.FindControl("lbLong")
这个找不到啊
用客户控件也不能找到
为什么啊

------解决方案--------------------
我不知道你输入问题还是?? e.Row.Calls[2]添加的控件

你在Calls[1]上找?


protected void Page_Load(object sender, EventArgs e)
{
DataTable _Table = new DataTable();
_Table.Columns.Add("asdf");
for (int i = 0; i != 10; i++)
{
_Table.Rows.Add(new object[] {i.ToString() });
}

GridView1.DataSource = _Table;
GridView1.DataBind();

Label a =new Label();
a.ID="A1";
a.Text="VVV";

GridView1.Rows[0].Cells[0].Controls.Add(a);

Response.Write(GridView1.Rows[0].Cells[0].Controls.Count.ToString());
}

这是没问题的.