-
CascadingDropDown - AJAX
Hi there,
I use three CascadingDropDown. They all get filled with SQL DB data.
In the first Dropdown you have to select the language. In the second you select a continent and in the third you select a country which belongs to the select continent from dropdown 2.
The continents in dropdown 2 are shown in the language you selected in dropdown 1.
My problem is, that it shows the countries in dropdown3 in all available languages, but I also want it to be filtered by selected language in dropdown 1.
I don't have an idea how to fix this problem.
I'm using asp.net, vb and ajax.
Please help!
Code:
<WebMethod()> _
Public Function GetLanguage( _
ByVal knownCategoryValues As String, _
ByVal category As String) As _
CascadingDropDownNameValue()
Dim ConnString As String = "Data Source=tim-pc\SQLExpress;Initial Catalog=master;Integrated Security=True;"
Dim SqlString As String = "SELECT * FROM Language"
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim cmd As SqlCommand = New SqlCommand(SqlString, conn)
Dim dtrLang As SqlDataReader
Dim languages As New List(Of CascadingDropDownNameValue)
conn.Open()
dtrLang = cmd.ExecuteReader
While dtrLang.Read
Dim strLangText As String = dtrLang("Language").ToString
Dim strLangID As String = dtrLang("Language_ID").ToString
languages.Add(New CascadingDropDownNameValue(strLangText, strLangID))
End While
Return languages.ToArray
End Function
<WebMethod()> _
Public Function GetContinent( _
ByVal knownCategoryValues As String, _
ByVal category As String) As _
CascadingDropDownNameValue()
Dim ConnString As String = "Data Source=..."
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim SqlString As String = "SELECT * FROM Continent WHERE Language_ID = @conti_id"
'System.Diagnostics.Debug.Print(SqlString)
Dim cmdFetchConti As SqlCommand = New SqlCommand(SqlString, conn)
Dim dtrConti As SqlDataReader
Dim kvConti As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim intContiId As Integer
If Not kvConti.ContainsKey("Language") Or Not Int32.TryParse(kvConti("Language"), intContiId) Then
Return Nothing
'System.Diagnostics.Debug.Print("no")
End If
'System.Diagnostics.Debug.Print(intContiId)
cmdFetchConti.Parameters.AddWithValue("conti_id", intContiId)
Dim continents As New List(Of CascadingDropDownNameValue)
conn.Open()
dtrConti = cmdFetchConti.ExecuteReader
While dtrConti.Read()
Dim strContiName As String = dtrConti("Continent").ToString
Dim strContiId As String = dtrConti("Continent_ID").ToString
System.Diagnostics.Debug.Print(strContiName)
System.Diagnostics.Debug.Print(strContiId)
continents.Add(New CascadingDropDownNameValue(strContiName, strContiId))
End While
Return continents.ToArray
End Function
<WebMethod()> _
Public Function GetCountry( _
ByVal knownCategoryValues As String, _
ByVal category As String) As _
CascadingDropDownNameValue()
Dim ConnString As String = "Data Source=..."
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim SqlString As String = "SELECT * FROM Country WHERE Continent_ID = @country_id ORDER BY Country ASC"
'System.Diagnostics.Debug.Print(SqlString)
Dim cmdFetchCountry As SqlCommand = New SqlCommand(SqlString, conn)
Dim dtrCountry As SqlDataReader
Dim kvCountry As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim intCountryId As Integer
If Not kvCountry.ContainsKey("Continent") Or Not Int32.TryParse(kvCountry("Continent"), intCountryId) Then
Return Nothing
'System.Diagnostics.Debug.Print("no")
End If
cmdFetchCountry.Parameters.AddWithValue("country_id", intCountryId)
Dim countries As New List(Of CascadingDropDownNameValue)
conn.Open()
dtrCountry = cmdFetchCountry.ExecuteReader
While dtrCountry.Read()
Dim strCountryName As String = dtrCountry("Country").ToString
Dim strCountryId As String = dtrCountry("Country_ID").ToString
countries.Add(New CascadingDropDownNameValue(strCountryName, strCountryId))
End While
Return countries.ToArray
End Function