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

gridview寻找控件方法
我在HeaderTemplate中放了一个dropdownlist控件,请问下怎么在除gridview_RowDataBound方法以外的地方获取该控件的对象

------解决方案--------------------
GridView.Rows[i].FindControl("XXX")
------解决方案--------------------
foreach (GridViewRow gr in gridView.Rows)
{
HiddenField hf=gr.FindControl("hf") as HiddenField;
if(hf!=null)
{
//
}


------解决方案--------------------
C# code

dropdownlist ddl = (dropdownlist)e.Row.Cells[3].FindControl("dropdownlist");

------解决方案--------------------
foreach (GridViewRow r in this.GridView1.Rows)
{
DropDownList ddl = r.FindControl("id") as DropDownList ;
}
------解决方案--------------------
C# code

        DropDownList ddl = this.GridView1.HeaderRow.FindControl("DropDownList1") as DropDownList;