ASP.NET using C#
If i had a two dropdown list box... when i select a first dropdown list value ( If i click India) the next next dropdown listbox automatically bring the value present in MSSQL column "State".. how could i make it... please send example Using C#....

Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 16, 2011, 9:42 AM EDT
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()
TextBox1.Text = ""
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"))
TextBox1.Text = reader("stdcode")
Loop
reader.Close()
con.Close()
End Sub
End Class
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 14, 2011, 10:27 AM EDT
More elaborate solution is to keep two- or three-letter ISO country codes behind both lists (so that value shown is country name and value selected is country code) and to operate with ISO codes rather than country names.
Zoran
Sam HobbsRank #107 · 20.5K reputationPosted Jul 14, 2011, 5:11 PM EDT
Manoj Tandon30 reputationPosted Jul 16, 2011, 6:42 AM EDT