Hi
I am using 2 dropdownlists such that corresponding to the item selected in the 1st dropdownlist only the related items will appear in the 2nd dropdownlist. The problem is that the 2nd dropdownlist is never populated. My code is:
Sub popdropdownlist1()
Dim myConnection1 As New SqlConnection(ConfigurationSettings.AppSettings("connectionString1"))
Const strSQLC As String = "select distinct name1, RTRIM(code1)as code1 from tabel1 where name1<> '' ORDER BY code1"
Dim myCommandC As New SqlCommand(strSQLC, myConnection1)
myConnectionC.Open()
Dim objDRC As SqlDataReader
objDRC=myCommandC.ExecuteReader(CommandBehavior.CloseConnection)
dropdownlist1.DataSource = objDRC
dropdownlist1.DataMember = "Table"
dropdownlist1.DataTextField = "name1"
dropdownlist1.DataValueField = "code1"
dropdownlist1.DataBind()
dropdownlist1.Items.Insert(0, New ListItem("-- Choose Name --"))
End Sub
The code to populate dropdownlist2 is:
Public Sub dropdownlist1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dropdownlist1.SelectedIndexChanged
Dim myConnectionD As New SqlConnection(ConfigurationSettings.AppSettings("connectionString1"))
Dim strV As String
strV = RTrim(dropdownlist1.SelectedItem.Value)
Const strSQLD As String = "select distinct deptCode,deptName From view1,table2 where deptCode like 'strV%' order by deptCode"
Dim myCommandD As New SqlCommand(strSQLD, myConnectionD)
myConnectionD.Open()
Dim objDRD As SqlDataReader
objDRD=myCommandD.ExecuteReader(CommandBehavior.CloseConnection)
dropdownlist2.DataSource = objDRD
dropdownlist2.DataMember = "Table"
dropdownlist2.DataTextField = "deptCode"
dropdownlist2.DataBind()
dropdownlist2.Items.Insert(0, New ListItem("-- Choose Dept --"))
end sub
So, i am passing the selected value of dropdownlist1 through string variable strV but never getting the dropdownlist2 populated although, strV is getting the value passed by dropdownlist1. If i hardcode it means if instaeed of parameter strV i pass some value in the select query of dropdownlist2, then the corresponding values do appear in dropdownlist2.
Also,AUTOPOSTBACK of both the dropdownlists is TRUE.
Please suggest some solution for this.
Regards
Monica