Hi,
I have the following code that should create a dropdown when the value in the another dropdown changes. So dropdown2 is created when value of dropdown1 is changed. And dropdown2 is also programatically associated with a datasource which is access in this case.
The dropdown gets created, but for some reason doesn't get populated. What am I doing wrong?
Protected Sub dropdown1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdown1.SelectedIndexChanged
Dim ds As New AccessDataSource
Dim dropdown2 As New DropDownList
Dim val As String
ds.DataFile = "<db path>"
ds.ID = "ds"
dropdown2.DataSource = ds
val = dropdown1.SelectedValue
If val = "xyz" Then
dropdown2.DataValueField = "xyz"
dropdown2.DataTextField = "xyz"
ds.SelectCommand = "select distinct xyz from Tbl;"
End If
form.Controls.Add(dropdown2)
form.Controls.Add(ds)
End Sub
Thx.