Solved

Get category from cascading dropdown extender

Posted on 2010-09-06
4
636 Views
Last Modified: 2012-05-10
I am having a problem getting the correct key name id from my cascading dropdown extender. I am getting no rows returned when there are rows available. I'm not getting a method error, just no rows returned, so I think I'm not getting the correct key. Below is my code. I'm using the same table and column for both dropdown lists. Just taking data for Day of Week on the 1st ddl, and Time of Day on the 2nd ddl, using the same datetime field. I'm not sure if on the category property of the cascadingdropdown list is correct, and the knowncategory values is correct on the webmethod.

Thank you.
<asp:DropDownList ID="LessonDay" runat="server" >
                    </asp:DropDownList><asp:CascadingDropDown ID="CascLessonDay" Category="Days"
       PromptText="Select Day"
        ServiceMethod="GetDay"
         ServicePath="~/Teachers.asmx"
          TargetControlID="LessonDay" runat="server">
                </asp:CascadingDropDown>


<asp:DropDownList ID="LessonTime" runat="server" >
                        </asp:DropDownList><asp:CascadingDropDown ID="CasclessonTime"
    category="Times" LoadingText="[Loading Class Times...]"
    ParentControlID="LessonDay" EmptyText="There are no times available on this day"
    PromptText="Please Select Time"
    ServiceMethod="GetTime"
    ServicePath="~/Teachers.asmx"
    TargetControlID="LessonTime"
    runat="server">
    </asp:CascadingDropDown>


<WebMethod()> _
    Public Function GetDay(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("BurgoyneMusicConnectionString").ConnectionString
        Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
       
        Dim strDayQuery As String = "Select id, InstrumentID, TeacherID, DATENAME(dw , EventStart) As Days, DATEPART(dw, EventStart), Available, EventStart, EventEnd FROM Events WHERE id IN (SELECT MAX(id) FROM Events WHERE InstrumentID = @InstrumentID And TeacherID = @TeacherID And Available <> 'False' Group by DATENAME(dw, EventStart) ) Order by DATEPART(dw, EventStart)"


        
        Dim cmdFetchDay As SqlCommand = New SqlCommand(strDayQuery, sqlConn)

        Dim dtrDay As SqlDataReader
        Dim kvDays As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

        Dim intTeachID As Integer
        If Not kvDays.ContainsKey("Instrument") Or Not Int32.TryParse(kvDays("Instrument"), intTeachID) Then
            Return Nothing
        End If       
        

        cmdFetchDay.Parameters.AddWithValue("@InstrumentID", intTeachID)
        Dim myDays As New List(Of CascadingDropDownNameValue)

        sqlConn.Open()
        dtrDay = cmdFetchDay.ExecuteReader

        While dtrDay.Read()
            Dim strDayName As String = dtrDay("Days").ToString
            Dim strDayId As String = dtrDay("id").ToString
            
            myDays.Add(New CascadingDropDownNameValue(strDayName, strDayId))
        End While

        Return myDays.ToArray
    End Function

    <WebMethod()> _
    Public Function GetTime(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
        Dim strConnection As String = ConfigurationManager.ConnectionStrings("BurgoyneMusicConnectionString").ConnectionString
        Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
        Dim strTimeQuery As String = "SELECT id, TeacherID, InstrumentID, right(convert(varchar(19), EventStart, 100),6) As Times, Available, DatePart(dw, EventStart), EventStart, EventEnd FROM Events WHERE id IN (SELECT MAX(id) FROM Events WHERE DatePart(dw, EventStart) = @DayOfWeekID and InstrumentID = @InstrumentID and TeacherID = @TeacherID and Available <> 'False'  Group by right(convert(varchar(19), EventStart, 100),6), DatePart(dw, EventStart) )"
                Dim cmdFetchTime As SqlCommand = New SqlCommand(strTimeQuery, sqlConn)

        Dim dtrTime As SqlDataReader
        Dim kvTime As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

        Dim intDayId As Integer

        If Not kvTime.ContainsKey("Days") Or Not Int32.TryParse(kvTime("Days"), intDayId) Then
            Return Nothing
        End If

        
       

        cmdFetchTime.Parameters.AddWithValue("@InstrumentID", "1")
        cmdFetchTime.Parameters.AddWithValue("@TeacherID", "1")
        cmdFetchTime.Parameters.AddWithValue("@DayofWeekID", intDayId)
        Dim myTime As New List(Of CascadingDropDownNameValue)

        sqlConn.Open()
        dtrTime = cmdFetchTime.ExecuteReader

        While dtrTime.Read()
            Dim strTimeName As String = dtrTime("Time").ToString
            Dim strTimeId As String = dtrTime("id").ToString

            myTime.Add(New CascadingDropDownNameValue(strTimeName, strTimeId))
        End While

        Return myTime.ToArray
    End Function

Open in new window

0
Comment
Question by:mlg101
  • 3
4 Comments
 
LVL 10

Expert Comment

by:Espavo
ID: 33616443
Is your first DDL being populated?
Dim intTeachID As Integer
        If Not kvDays.ContainsKey("Instrument") Or Not Int32.TryParse(kvDays("Instrument"), intTeachID) Then
            Return Nothing
End If      
I don't see where you are pulling a value for "Instrument" from...
Espavo
0
 
LVL 1

Author Comment

by:mlg101
ID: 33618429
Yes, sorry, I was trying to simplify it. I have actually 4 ddls with cascading. The first one here is getting its value from Instrument and it is working fine. I am just having problems with the last ddl, which shares the same table column and row as its parent ddl.
0
 
LVL 1

Author Comment

by:mlg101
ID: 33621334
I clarified my quesiton in a different question, because I narrowed my problem down, but still need a solution: you can find it at the link below or click on my username to find it. Thank you.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_26457119.html
0
 
LVL 1

Accepted Solution

by:
mlg101 earned 0 total points
ID: 33630058
I figured it out. You can pass whatever variable from the previous cascading dropdown to the next, you just pull it out with the sqldatareader, then add it to the CascadingDropdownnamevalue, like I did below. I wanted to get DateName(dw, EventStart) in the ddl text, but I wanted to return DatePart(dw, EventStart) to the next ddl. So I had the sqldatareader read both "Days" and "Day2", then passed both (strDayName, strDay2ID) in the cascadingdropdownnamevalue. My problem was I thought you had to pass the table's primary key to the next dropdownlist, but I was wrong!

While dtrDay.Read()
            Dim strDayName As String = dtrDay("Days").ToString
            Dim strDayId As String = dtrDay("id").ToString
            Dim strDay2Id As String = dtrDay("Day2").ToString

            myDays.Add(New CascadingDropDownNameValue(strDayName, strDay2Id))

           End While

        Return myDays.ToArray

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
performance issue in asp web 5 38
Jquery datatables integration with ASP.NET MVC, bootstrap 3 23
Linq asp.net mvc 13 17
Generate Unique ID in VB.NET 21 69
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question