Link to home
Start Free TrialLog in
Avatar of nduguyettu
nduguyettu

asked on

Populating a Dropdown list

I have three Dropdown lists. The second and third Dropdown lists are populated basing on the selected itetm in the previous Dropdown list. I use the SelectedIndexChanged procedure to populate the Dropdown lists. It so happens that when there is only one item in the previus Dropdown list, the next Dropdown list cannot be populated.

How can I solve this problem?

Nduguyettu
Private Sub aDistrictOfBirth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aDistrictofBirth.SelectedIndexChanged
        Dim t As New NameSpaceNdugu.SQLService
        Dim ds As DataSet
 
        sql = "Select Distinct CountyName from District where DistrictName = '" & aDistrictOfBirth.SelectedItem.Value & "'"
        ds = t.Populate(conStr, sql)
        aCounty.DataSource = ds.Tables("vTable").DefaultView
        aCounty.DataBind()
    End Sub
 
    Private Sub aCounty_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aCounty.SelectedIndexChanged
        Dim t As New NameSpaceNdugu.SQLService
        Dim ds As DataSet
 
        sql = "Select Distinct SubCountyName from District where CountyName = '" & aCounty.SelectedItem.Value & "'"
        ds = t.Populate(conStr, sql)
        aSubCounty.DataSource = ds.Tables("vTable").DefaultView
        aSubCounty.DataBind()
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nduguyettu
nduguyettu

ASKER

This fully solved the question I asked and am very grateful. But another situation is that by default a district is displayed in the Dropdown list but one cannot click on it to populate the next dropdown list. One needs to click the next item before going back to the first. How can such a problem be solved?

Nduguyettu