簡體   English   中英

在gridview中填充另一個下拉的selectedindex上的一個下拉列表

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM