各位园友大家好,
我在GridView模板列的编辑列中放入一个DropDownList,如下.
<EditItemTemplate>
<asp:DropDownList ID="gvw_ddlParentID" runat="server">
</asp:DropDownList>
</EditItemTemplate>
后台取得数据源,例如部门.需要将部门绑定到这个DropDownList中.
我试了在RowEditing事件中:
((DropDownList)gvwGroup.Rows[e.NewEditIndex].FindControl("gvw_ddlParentID"))
结果找不到这个控件?
各位园友帮忙看下原因,谢谢~
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; Bindlist(); DropDownList ddl = ((DropDownList)GridView1.Rows[e.NewEditIndex].FindControl("gvw_ddlParentID")); ddl.Items.Add(new ListItem("fff", "0")); ddl.DataBind(); }
要先设置gridview的EditIndex,在重新绑定Gridview,才可以查找到该行EditItemTemplate里的DropDownList。
非常感谢!
在 protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
中找到控件 DropDownList ddl= (DropDownList)e.Row.FindControl("ddl_ID");