I have read several similar post but yet no solution
Hello I am tryingto use Ajax CascadingDropDown with a database.
My database structure is:
IssueID(PK)
GroupID
ParentIssueID
IssueName
There are 3 dropdown list.
The first dropdown list retrieves data from the datble with parent ID = -1.
While the second drop down list retrieves it info based on the selected value (ID) of the first dropdownlist.
say we have in the table:
IssueID GroupID ParentIssueID IssueName
1 1 -1 Housing
2 1 1 Electronics
3 2 -1 Garden
4 1 2 Microwave
So, in the case the first dropdown retrives all data from the table with (ParentIssueID= -1) so here we have: Housing and Garden. both IssueIS and IssueName are returned.
Onselecting (say housing), the second dropdown retrieves any row with -> ParentIssueID = IssueID(value of ddl) of the selected value is the first dropdown. Here we have Electronics retured.
The third dropdown returns the list of rows based of the value of the selected ddl. Here we have Microwave.
Thus we have:
First ddl: Housing
Second ddl: Electronics
Third ddl: Microwave
Below is my web method:
<WebMethod()> _
Public Function GetMainIssue(ByVal knownCategoryValues As Integer, ByVal category As String) As CascadingDropDownNameValue()
Dim maindepth As Integer = 1
Dim mainIssueAdapter As New mainIsseDataTableAdapters.GetDepthTableAdapter()
Dim mainIssue As mainIsseData.GetDepthDataTable = mainIssueAdapter.GetMainIssue(maindepth)
Dim values As New List(Of CascadingDropDownNameValue)()
For Each dr As DataRow In mainIssue
Dim IssueName As String = DirectCast(dr("IssueName"), String)
Dim IssueID As Integer = CInt(dr("IssueID"))
values.Add(New CascadingDropDownNameValue(IssueName, IssueID))
Next
Return values.ToArray()
End Function
<WebMethod()> _
Public Function GetSubIssue(ByVal knownCategoryValues As Integer, ByVal category As String) As CascadingDropDownNameValue()
Dim kv As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim IssueID As Integer
If Not kv.ContainsKey("mainIssue") OrElse Not Int32.TryParse(kv("mainIssue"), IssueID) Then
Return Nothing
End If
Dim subIssuesAdapter As New subIssueDataTableAdapters.GetAllCategoryTableAdapter()
Dim subIssue As subIssueData.GetAllCategoryDataTable = subIssuesAdapter.GetSubIssue(IssueID)
Dim values As New List(Of CascadingDropDownNameValue)()
For Each dr As DataRow In subIssue
values.Add(New CascadingDropDownNameValue(DirectCast(dr("IssueName"), String), dr("IssueID").ToString()))
Next
Return values.ToArray()
End Function
In my aspx file I have
<asp:DropDownList id="drpMainCategory" runat="server">
<cc1:cascadingdropdown id="CascadingDropDown2" runat="server" loadingtext="[Loading...]"
prompttext="Please select a Main Issue" servicepath="../UpdateDropDown.asmx"
targetcontrolid="drpMainCategory" Category="getmain" ServiceMethod="GetMainIssue"></cc1:cascadingdropdown>
I get an error(500 or 12030) when I run it.
Also, I cant figure out what exactly the category field is for <cc1:cascadingdropdown control. how do I optain it. Any comments or similar code to help would be greatly appreciated.
Thanks
Please refer to this thread: http://forums.asp.net/t/1122659.aspx
No comments:
Post a Comment