2016-04-15 19 views
-1

私は特定の都市を選択すると、次のドロップダウンリスト項目に異なる選択肢を表示する配信アドレス機能を持っています。ここに私のhtmlコードは次のとおりです。ifドロップダウンリスト項目の文

<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> 

例えば、私はITEM1を選択するように、それは別の目的地が表示されます。 item2の場合、別の宛先の集合などが表示されます。あなたは私と共有するかもしれないこれに関するどんなトリックですか?

if (DropDownList1.SelectedItem.Text.Equals("Las Pinas")) 
     { 
      DropDownListCity2.Items.Add("Almanza"); 
      DropDownListCity2.Items.Add("Almanza Dos"); 
     } 

を、それは何もしません:あなたは

私が試したの背後に、このコードを持つ感謝。助けてください。

+0

。 –

答えて

0

それを考え出しました。

ドロップダウンリストでautopostback = "true"を設定します。

<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> 

その後、後ろのコードでこれを置く:目的地は、同様に、ドロップダウンリストの項目に表示されます方法により

if (DropDownList1.SelectedItem.Text.Equals("Las Pinas")) 
     { 
      DropDownListCity2.Items.Add("Almanza"); 
      DropDownListCity2.Items.Add("Almanza Dos"); 
     } 
関連する問題