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 NayakPosted Jul 16, 2011, 1:42 PM
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
Manoj TandonPosted Jul 16, 2011, 10:42 AM
Sam HobbsPosted Jul 14, 2011, 9:11 PM
Zoran HorvatPosted Jul 14, 2011, 2:27 PM
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