Voglio avere una funzione di indirizzo di consegna in cui se scelgo una città specifica, mostrerà diverse scelte sulla successiva voce dell'elenco a discesa. Ecco il mio codice html:
<td>
City
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" placeholder="Income Range...">
<asp:ListItem Value="item1" Selected="True">--Select--</asp:ListItem>
<asp:ListItem Value="item2" Selected="True">--Las Pinas--</asp:ListItem>
<asp:ListItem Value="item3" Selected="True">--Muntinlupa--</asp:ListItem>
<asp:ListItem Value="item4" Selected="True">--Paranaque--</asp:ListItem>
<asp:ListItem Value="item5" Selected="True">--Pasay--</asp:ListItem>
</asp:DropDownList>
</td>
Ad esempio, scelgo item1, mostrerà diverse destinazioni. se item2, mostrerà un altro set di destinazioni e così via. qualche trucco su questo che potresti condividere con me? grazie
ho provato ad avere questo codice dietro:
if (DropDownList1.SelectedItem.Text.Equals("Las Pinas"))
{
DropDownListCity2.Items.Add("Almanza");
DropDownListCity2.Items.Add("Almanza Dos");
}
ma non fa nulla. per favore aiutatemi
risposte:
0 per risposta № 1capito comunque.
imposta autopostback = "true" nell'elenco a discesa.
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Value="item1" Selected="True">--Select--</asp:ListItem>
<asp:ListItem Value="item2" >Las Pinas</asp:ListItem>
<asp:ListItem Value="item3" >Muntinlupa</asp:ListItem>
<asp:ListItem Value="item4" >Paranaque</asp:ListItem>
<asp:ListItem Value="item5" >Pasay</asp:ListItem>
</asp:DropDownList>
<td>
<asp:DropDownList ID="DropDownListCity2" runat="server" >
</asp:DropDownList>
</td>
quindi metti questo sul codice:
if (DropDownList1.SelectedItem.Text.Equals("Las Pinas"))
{
DropDownListCity2.Items.Add("Almanza");
DropDownListCity2.Items.Add("Almanza Dos");
}