Hi,
There are three dropdownlist
1.dropdown_city
2.dropdown_state
3.dropdown_country
when i choose a city from the dropdown_city,its corresponding state and country will be shown in the respective two dropdownlist.
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaish MathewsRank #225 · 11K reputationPosted Apr 27, 2010, 9:02 PM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 28, 2010, 1:57 AM EDT
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
con.Open()
str = "select * from area"
com = New SqlCommand(str, con)
Dim reader As SqlDataReader = com.ExecuteReader
While reader.Read
DropDownList1.Items.Add(reader("city"))
End While
reader.Close()
con.Close()
End If
DropDownList2.Items.Clear()
DropDownList3.Items.Clear()
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
con.Open()
str = "select * from area where city='" & DropDownList1.SelectedValue & "'"
com = New SqlCommand(str, con)
Dim reader As SqlDataReader = com.ExecuteReader
Do While reader.Read
DropDownList2.Items.Add(reader("state"))
DropDownList3.Items.Add(reader("country"))
Loop
reader.Close()
con.Close()
End Sub
End Class