Hai all,,
Currently I'm writing code in ASP.NET using VB language. I got an issue regarding dropdownlist. In my form, I have a treeview and a dropdownlist which are populated with data from database. When I click a node in treeview, the dropdownlist should be populated with values based on the selected node. This works fine at the first time page loading. But when I move to the other node of the treeview (which should trigger different dataset for the dropdownlist), the items inside the dropdownlist aren't changed. No matter how many times I change the selected node of the treeview, the dropdownlist always keeps the items from the first time it is populated. What should I do to make it populated dynamically,based on the treeview selected node?
I put the code to populate the dropdownlist inside the Treeview_SelectedNodeChanged method.
Here is my code:
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged
Dim dataReader As SqlDataReader
Dim cmdPro As SqlCommand
Lbl_model.Text = Nothing
Select Case TreeView1.Nodes(i).Value.ToString
Case "OH 1521"
Lbl_model.Text = "TblCat_OH1521"
Case "OH 1526"
Lbl_model.Text = "TblCat_OH1526"
Case "OH 1626"
Lbl_model.Text = "TblCat_OH1626"
Case "O500R 1830"
Lbl_model.Text = "TblCat_OH1830"
Case "ENGINE 924"
Lbl_model.Text = "TblCat_ENGINE924"
End Select
cmdPro = New SqlCommand("select distinct Page from " & Lbl_model.Text & " order by Page", con)
con.Open()
dataReader = cmdPro.ExecuteReader()
While dataReader.Read
part_Page.Items.Add(dataReader(0).ToString())
End While
con.Close()
'part_Page is the dropdownlist'
End Sub
I'm quite newbie in .NET. So any help would be very appreciated. Thanks a lot :)
Best regards,
Dyah