質問

i have 4 dropdownlist. when i change the 1st dropdown, onselectindexchanged i need to change all the remaining dropdown values. I am working on it but i could change only the corresponding or next dropdown value on onselectindexchanged. Please provide me any example or guide me to any good link. Pls help.. Thanks in advance.

役に立ちましたか?

解決

You need to set AutoPostBack of all dropdowns to true and need to add SelectedIndexChanged event for first three drop downs. On SelectedIndexChanged of first dropdown you need to set selected value of second and it will fire SelectedIndexChanged of second and there you will have code to set selected index of third and similarly you will do on wards.

In Html

<asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist1_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="dropdownlist2" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist2_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="dropdownlist3" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropdownlist3_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>

<asp:DropDownList ID="dropdownlist4" runat="server" AutoPostBack="true" >
<asp:ListItem Value="1">1</asp:ListItem> 
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>

1 2

In code behind

protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist2.SelectedIndex = someIndexValue;
}

protected void dropdownlist2_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist3.SelectedIndex = someIndexValue;
}

protected void dropdownlist3_SelectedIndexChanged(object sender, EventArgs e)
{
       dropdownlist4.SelectedIndex = someIndexValue;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top