查找GridView里的模板列里的子控件问题?
<asp:TemplateField HeaderText="行政区划2">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Width="100%">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
GridView里添加了一个模板列,模板列的EditItemTemplate里加有一个DropDownList 其ID="DropDownList1"。
现要找到该子控件,并其进行值的绑定,代码如下:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
string sql = "SELECT * FROM NEM2_T01_03_01 ";
HybInfo.HybDAO.DynamicEntityService hybDAO = new HybInfo.HybDAO.DynamicEntityService();
((DropDownList)e.Row.FindControl("DropDownList1")).DataSource = hybDAO.QueryBySQL(sql).DataSource;
((DropDownList)e.Row.FindControl("DropDownList1")).DataTextField = "F01030102";
((DropDownList)e.Row.FindControl("DropDownList1")).DataValueField = "F01030101";
((DropDownList)e.Row.FindControl("DropDownList1")).DataBind();
}
运行提示找不该子控件?请各位帮忙找找原因。