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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Apr 28, 2010, 5:57 AM
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
Jaish MathewsPosted Apr 28, 2010, 1:02 AM