[英]Populate one combobox on the selectedindexchanged event of another combox
[英]to populate one dropdown on selectedindexchanged of another inside gridview
我有连续两个下拉菜单说国家和州的gridview,国家下拉列表的变化我想当网格处于编辑状态时填充状态下拉列表。 我同时在网格的RowEditing事件中获得了下拉列表,在网格的第一个下拉列表中附加了selectedindexchanged事件。问题是如何在国家下拉列表的selectedindexchange事件中获得第二个下拉列表,即状态下拉列表。
如果在下拉选择更改事件之前发生RowEditing
事件,则可以在应用程序中存储对当前Row
引用。 然后在下拉更改事件中获取此行。
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl1 = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl1.NamingContainer;
if (row != null)
{`enter code here`
DropDownList ddl2 = (DropDownList)row.FindControl("DropDownList3");
{
//call the method for binding the second DDL based on the selected item on the first DDL
DataTable dt = BindDropDownList(ddl1.SelectedItem.Text);
ddl2.DataTextField = "Field1";
ddl2.DataValueField = "Field2";
ddl2.DataBind();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.