GridView中两个DropDownList联动
Html:
<asp:UpdatePanel runat="server" ID="AccountUpdate" UpdateMode="Conditional" >
<ContentTemplate>
<asp:GridView ID="gridAccount" runat="server" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="选择一" ItemStyle-Width="15%">
<ItemTemplate>
<asp:DropDownList ID="ddlA" OnSelectedIndexChanged="ddlA_SelectedIndexChanged" AutoPostBack="true" runat="server" Width="50px">
<asp:ListItem Value="">全部</asp:ListItem>
<asp:ListItem Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="选择二" ItemStyle-Width="15%">
<ItemTemplate>
<asp:DropDownList ID="ddlB" runat="server" Width="50px">
<asp:ListItem Value="">全部</asp:ListItem>
<asp:ListItem Value="1">是</asp:ListItem>
<asp:ListItem Value="0">否</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
CS:
public void ddlA_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlA= (DropDownList)sender;//获取现在的事件触发者:
GridViewRow gvr = (GridViewRow)ddlA.NamingContainer;//ddlA同属于在一个NamingContainer下
DropDownList ddlB= (DropDownList)gvr.FindControl("ddlB");//找到ddlA的DropDownList
ddlB.Enabled = false;
}