1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to bind two dropdown list in asp.net?

Discussion in 'C#' started by raspms, Apr 19, 2012.

  1. #1
    hello,
    i have two dropdown list in one form.i have to select a state from one dropdown list then in 2nd dropdown list should contain the cities related to that state.
    how can i do that?
    please give me proper code for that..
    SEMrush
     
    raspms, Apr 19, 2012 IP
    SEMrush
  2. geekstrack

    geekstrack Member

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    You should use code like this
    <asp:DropDownList ID="DropDownList1" runat="server" Height="40px" Width="206px">
    <asp:ListItem Value="India">delhi</asp:ListItem>
    <asp:ListItem Value="India">Mumbai</asp:ListItem>
    <asp:ListItem Value="USA">New York</asp:ListItem>
    <asp:ListItem Value="USA">Washington</asp:ListItem>
    </asp:DropDownList>
    in value field add countries name of cities dropdown
    and in country dropdown add countries name in lists...

    on selected index changed event of country dropdown just match values of cities dropdown to lists of countries dropdown.... and show them as per their values like you select India as countries then by if condition check their values with cities drop down you can see the above code so if you select india it will show you delhi, mumbai... similarly if you select USA it will show you newyork washington...

    You have other ways also to do this work you can do this with database where you have to create two tables...
     
    geekstrack, Apr 22, 2012 IP