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

nduguyettuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
Add the second and thiord bind in Sub and whenevenr requied call that sub like below
Private Sub aDistrictOfBirth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aDistrictofBirth.SelectedIndexChanged
        Bind1()
        Bind2()
    End Sub
 
    Private Sub aCounty_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles aCounty.SelectedIndexChanged
        Bind2()
    End Sub
    Sub Bind1()
        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
 
    Sub Bind2()
        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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nduguyettuAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.