接着刚才的问题,ASPxGridView的编辑模板
接着刚才的问题,把DropDownList放到ASPxGridView的编辑模板里,录入数据时候用,为什么就找不到DropDownList了,怎么解决。谢谢
[解决办法]
循环遍历查找或者在
GridView_RowDataBound
protected void gdv_Elec_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (((DropDownList)e.Row.FindControl("drop_Location")) != null)
{
DropDownList drop_Location = (DropDownList)e.Row.FindControl("drop_Location");
drop_Location.Items.Clear();
DataTable dt = ef.GetLocation();
drop_Location.DataSource = dt;
drop_Location.DataTextField = dt.Columns["LOCATION"].ToString();
drop_Location.DataValueField = dt.Columns["LOCATION"].ToString();
drop_Location.DataBind();
}
}
protected void drop_Location_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drop_Location = (DropDownList)sender;
System.Web.UI.WebControls.GridViewRow dvr = (System.Web.UI.WebControls.GridViewRow)drop_Location.NamingContainer;
DropDownList drop_name = (DropDownList)dvr.FindControl("drop_name");
//drop_name.Items.Clear();
DataTable dt = ef.GetNameBYLocation(drop_Location.SelectedItem.Text);
drop_name.DataSource = dt;
drop_name.DataTextField = dt.Columns["ECLE_NAME"].ToString();
drop_name.DataValueField = dt.Columns["ECLE_NAME"].ToString();
drop_name.DataBind();
}