Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
there are two combo boxs state and district, the values are bind from database. when i select state based upon selected item district has to display
Posted
Comments
AmitGajjar 25-May-12 2:47am    
homework ?

Please refer: This is exact one with source code.

Creating Cascading DropDownLists[^]
This article explains you how to create a Cascading DropDownLists in ASP.Net that is DropDownLists which depend on the previous or parent DropDownList for the data.

C# - Cascading combo box results in a Windows[^]
Cascading combo box results in a Windows[^]
Similar discussion: How to do cascading combobox in windows application[^]
 
Share this answer
 
v2
Comments
Maciej Los 25-May-12 4:44am    
Super! +5!
Prasad_Kulkarni 25-May-12 4:47am    
Thank you Isomac!
try like this

VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
      If ComboBox1.SelectedItem.ToString() = "AP" Then
          ComboBox2.Items.Add("Medak")
 ComboBox2.Items.Add("Hyd")
'or bind combobox from db  also bind combobox2 here like  
 Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "select dist from district  where state='"+combobox1.selecteditem.tostring()+"'"
        con.Open()
        dr = cmd.ExecuteReader()
        If (dr.HasRows = True) Then
            While (dr.Read())
               ComboBox2.Items.Add(dr("dist").ToString())

            End While
        End If
        dr.Close()
        con.Close()
      End If

  End Sub
 
Share this answer
 
v2

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