dropdownlist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shalini166
    New Member
    • Apr 2008
    • 70

    dropdownlist

    hi

    I need to populate the respective states from the states dropdownlist when a user chooses a country from the country dropdownlist. Similary when the state is selected from the states dropdownlist the corresponding cities should get displayed in the cities dropdownlistbox . Pls provide me with the coding? Here is the following code which i developed.

    example(c#.net)

    Private Sub fillcountry()
    ddlcountry.Item s.Add("India")
    ddlcountry.Item s.Add("UK")
    ddlcountry.Item s.Add("USA")
    ddlcountry.Item s.Add("Germany" )
    End Sub
    Private Sub fillstate()
    'list of states in india
    ddlstate.Items. Add("Tamilnadu" )
    ddlstate.Items. Add("AndhraPrad esh")
    ddlstate.Items. Add("Kerela")
    ddlstate.Items. Add("MadhyaPrad esh")
    'list of states in UK
    ddlstate.Items. Add("Yorkshire" )
    ddlstate.Items. Add("London")
    ddlstate.Items. Add("Surrey")
    ddlstate.Items. Add("Manchester shire")
    'list of states in USA
    ddlstate.Items. Add("Florida")
    ddlstate.Items. Add("California ")
    ddlstate.Items. Add("Atlanta")
    ddlstate.Items. Add("Chicago")
    'list of states in Germany
    ddlstate.Items. Add("Berlin")
    ddlstate.Items. Add("Hamberg")
    ddlstate.Items. Add("Frankfurt" )
    ddlstate.Items. Add("Munich")
    End Sub
    Private Sub fillcity()
    'list of cities in india
    ddlstate.Items. Add("Mumbai")
    ddlstate.Items. Add("Chennai")
    ddlstate.Items. Add("Kolkatta")
    ddlstate.Items. Add("Delhi")
    'list of cities in UK
    ddlstate.Items. Add("Yorkshire" )
    ddlstate.Items. Add("London")
    ddlstate.Items. Add("Surrey")
    ddlstate.Items. Add("Manchester shire")
    'list of cities in USA
    ddlstate.Items. Add("Florida")
    ddlstate.Items. Add("California ")
    ddlstate.Items. Add("Atlanta")
    ddlstate.Items. Add("Chicago")
    'list of cities in Germany
    ddlstate.Items. Add("Berlin")
    ddlstate.Items. Add("Hamberg")
    ddlstate.Items. Add("Frankfurt" )
    ddlstate.Items. Add("Munich")
    End Sub
  • malav123
    New Member
    • Feb 2008
    • 217

    #2
    whatever you wants just put it in ddlcountry_sele ctedindexchaged event....
    just like if ddlcountry.sele ctedvalue="indi a" then
    ddlstate.items. add("")
    ddlstate.items. add("")
    ddlstate.items. add("")
    else if ddlcountry.sele ctedvalue="UK" then
    ddlstate.items. add("")
    ddlstate.items. add("")
    ddlstate.items. add("")
    end if

    just code it yourself it's easy.....

    Comment

    • kunal pawar
      Contributor
      • Oct 2007
      • 297

      #3
      First set property Autopostback=tr ue for drop down control and write ur fill code in selected index changed event



      Private Sub fillcountry()
      ddlcountry.Item s.Add("India")
      ddlcountry.Item s.Add("UK")
      ddlcountry.Item s.Add("USA")
      ddlcountry.Item s.Add("Germany" )
      End Sub

      Protected Sub ddlcountry_Sele ctedIndexChange d(ByVal sender As Object, ByVal e As System.EventArg s) Handles ddlstInstituteN ame.SelectedInd exChanged

      'CAll ur fill state method for selected item text
      fillstate()

      End Sub

      Private Sub fillstate()
      'list of states in india
      ddlstate.Items. Add("Tamilnadu" )
      ddlstate.Items. Add("AndhraPrad esh")
      ddlstate.Items. Add("Kerela")
      ddlstate.Items. Add("MadhyaPrad esh")
      'list of states in UK
      ddlstate.Items. Add("Yorkshire" )
      ddlstate.Items. Add("London")
      ddlstate.Items. Add("Surrey")
      ddlstate.Items. Add("Manchester shire")
      'list of states in USA
      ddlstate.Items. Add("Florida")
      ddlstate.Items. Add("California ")
      ddlstate.Items. Add("Atlanta")
      ddlstate.Items. Add("Chicago")
      'list of states in Germany
      ddlstate.Items. Add("Berlin")
      ddlstate.Items. Add("Hamberg")
      ddlstate.Items. Add("Frankfurt" )
      ddlstate.Items. Add("Munich")
      End Sub

      same for cities

      Comment

      • malav123
        New Member
        • Feb 2008
        • 217

        #4
        Originally posted by kunal pawar
        First set property Autopostback=tr ue for drop down control and write ur fill code in selected index changed event



        Private Sub fillcountry()
        ddlcountry.Item s.Add("India")
        ddlcountry.Item s.Add("UK")
        ddlcountry.Item s.Add("USA")
        ddlcountry.Item s.Add("Germany" )
        End Sub

        Protected Sub ddlcountry_Sele ctedIndexChange d(ByVal sender As Object, ByVal e As System.EventArg s) Handles ddlstInstituteN ame.SelectedInd exChanged

        'CAll ur fill state method for selected item text
        fillstate()

        End Sub

        Private Sub fillstate()
        'list of states in india
        ddlstate.Items. Add("Tamilnadu" )
        ddlstate.Items. Add("AndhraPrad esh")
        ddlstate.Items. Add("Kerela")
        ddlstate.Items. Add("MadhyaPrad esh")
        'list of states in UK
        ddlstate.Items. Add("Yorkshire" )
        ddlstate.Items. Add("London")
        ddlstate.Items. Add("Surrey")
        ddlstate.Items. Add("Manchester shire")
        'list of states in USA
        ddlstate.Items. Add("Florida")
        ddlstate.Items. Add("California ")
        ddlstate.Items. Add("Atlanta")
        ddlstate.Items. Add("Chicago")
        'list of states in Germany
        ddlstate.Items. Add("Berlin")
        ddlstate.Items. Add("Hamberg")
        ddlstate.Items. Add("Frankfurt" )
        ddlstate.Items. Add("Munich")
        End Sub

        same for cities

        Hi Kunal,
        from your suggested code, i think it will fill all the state for all country and it will fill all the cities for all the state because there is no any specific condition for specific country....

        Comment

        Working...