![](/img/trans.png)
[英]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.