在一个GridView中绑定2个DropDownList,分别是ddl_A,ddl_B,都用模板列方式绑定。B的实际内容需要根据A的当前选定内容来获取,怎样将A和B关联起来呢?ddl_A的SelectedIndexChanged事件写在哪里呢?
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="da_SelectedIndexChanged" >
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
protected void da_SelectedIndexChanged( object sender, EventArgs e )
{
string[] b = { "A", "B", "C" };
DropDownList da = (DropDownList)sender;
System.Web.UI.WebControls.GridViewRow dvr = (System.Web.UI.WebControls.GridViewRow)da.NamingContainer;
DropDownList db = (DropDownList)dvr.FindControl("db");
for (int i = 0 ; i < b.Length ; i++)
{
db.Items.Add(b[i]);
}
db.SelectedIndex = da.SelectedIndex;
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="da_SelectedIndexChanged" >
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
protected void da_SelectedIndexChanged( object sender, EventArgs e )
{
string[] b = { "A", "B", "C" };
DropDownList da = (DropDownList)sender;
System.Web.UI.WebControls.GridViewRow dvr = (System.Web.UI.WebControls.GridViewRow)da.NamingContainer;
DropDownList db = (DropDownList)dvr.FindControl("db");
for (int i = 0 ; i < b.Length ; i++)
{
db.Items.Add(b[i]);
}
db.SelectedIndex = da.SelectedIndex;