Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have two dropdownlist one is for city (ddlcity) and another is for location (ddllocation). I want when I select a city from city dropdownlist then only that city location should show in location dropdownlist.
for example: lets select gurgaon city in ddlcity then only location in gurgaon should show in ddllocation.

Thank You.
Posted
Updated 12-Jul-11 2:24am
v3

If the number of cities and their locations are not very much, then you can use JavaScript (or better jQuery to do the same). Search Google for "cascading dropdownlist javascript" and you will get thousands of example.

The other way is to get the details from server. Check this out - CascadingDropDown[^]. The example tells how to use it as well.

Hope this helps!
 
Share this answer
 
Protected Sub ddlcity_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim cmd As New SqlCommand("select location  from mstCities where  city = '" & ddlcity.SelectedItem.Text & "'", con)
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            ddllocation.DataSource = dr
            ddllocation.DataBind()
        End While
        con.Close()
    End Sub

<pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900