Solved

Change time zone in Cascading DropDown

Posted on 2011-02-15
13
509 Views
Last Modified: 2012-05-11
I'm populating a cascading ddl using webservice for systemtimezones, then I have cascading ddls, using the webservice, and want to convert the date/time in the last ddl (GetTime),  based on the 1st ddl (GetTimeZone Webmethod).

This line of code, which is close to the bottom of my code below, does not return any rows:
Dim strTimeName As String = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dtrTime("EventStart"), TimeZoneInfo.Local.Id, intZoneId.ToString()).ToString()

Any ideas on how to get it to work in this webservice? I have a similar code working on .aspx page using one ddl and 2 labels but this is different.

Thank you.
<WebMethod()> _
    Public Function GetTimeZone(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()



        Dim tzi As ReadOnlyCollection(Of TimeZoneInfo)
        tzi = TimeZoneInfo.GetSystemTimeZones()



        Dim myTimeZone As New List(Of CascadingDropDownNameValue)
        For Each timeZone As TimeZoneInfo In tzi
            Dim Zone As String = CStr(timeZone.DisplayName)
            Dim ZoneID As String = CStr(timeZone.Id)

            myTimeZone.Add(New CascadingDropDownNameValue(Zone, ZoneID))
            'End While
        Next timeZone
        Return myTimeZone.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 Or InstrumentID = 0) and TeacherID = @TeacherID and Available <> 'False'  Group by right(convert(varchar(19), EventStart, 100),6), DatePart(dw, EventStart) )Order by right(convert(varchar(19), EventStart, 100),6)"

        Dim strTimeQuery As String = "SELECT id, TeacherID, InstrumentID, Available, DatePart(dw, EventStart), EventStart, EventEnd FROM Events WHERE id IN (SELECT MAX(id) FROM Events WHERE DatePart(dw, EventStart) = @DayOfWeekID and (InstrumentID = @InstrumentID Or InstrumentID = 0) and TeacherID = @TeacherID and Available <> 'False'  Group by right(convert(varchar(19), EventStart, 100),6), DatePart(dw, EventStart) )Order by right(convert(varchar(19), EventStart, 100),6)"
        Dim cmdFetchTime As SqlCommand = New SqlCommand(strTimeQuery, sqlConn)

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

        Dim kvtime2 As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
        Dim intDayID2 As Integer
        If Not kvtime2.ContainsKey("day2") Or Not Int32.TryParse(kvtime2("day2"), intDayID2) Then
            Return Nothing
        End If


        Dim intDayId As Integer
        If Not kvTime.ContainsKey("day2") Or Not Int32.TryParse(kvTime("day2"), intDayId) Then
            Return Nothing
        End If

        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
        Dim kvTeach As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
        Dim intInstId As Integer
        If Not kvTeach.ContainsKey("Teacher") Or Not Int32.TryParse(kvTeach("Teacher"), intInstId) Then
            Return Nothing
        End If

cmdFetchTime.Parameters.AddWithValue("@InstrumentID", intTeachID)
        cmdFetchTime.Parameters.AddWithValue("@TeacherID", intInstId)
        cmdFetchTime.Parameters.AddWithValue("@DayofWeekID", intDayID2)
        Dim myTime As New List(Of CascadingDropDownNameValue)

        sqlConn.Open()
        dtrTime = cmdFetchTime.ExecuteReader

 While dtrTime.Read()

            Dim kvZone As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

            Dim intZoneId As Integer

            If Not kvTeach.ContainsKey("Zone") Or Not Int32.TryParse(kvZone("Zone"), intZoneId) Then
                Return Nothing
            End If

Dim strTimeName As String = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dtrTime("EventStart"), TimeZoneInfo.Local.Id, intZoneId.ToString()).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
13 Comments
 
LVL 5

Expert Comment

by:Siyamala
ID: 34905499
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34905995
0
 
LVL 1

Author Comment

by:mlg101
ID: 34908254
Thanks, but I think I need more than just a link or two to figure this out.

@Siyamala, knowing how the cascading dropdown works was a good article, but I think my VB needs some help to make this work. And I already have the ddl of time zones populated with system time zones.

@codecruiser, I got my code from that link and modified it to what I have now.

from the code below, I think the only thing that needs to be fixed is the "intZoneID.ToString()", where I need to get the value from the time zone list, the same way as codecruiser's link code does on the aspx page.

Dim strTimeName As String = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dtrTime("EventStart"), TimeZoneInfo.Local.Id, intZoneId.ToString()).ToString()


0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34908364
Have you populated the zones DDL? Have you set the ValueMember as well with ZoneIDs? If yes then you can use that ddlzones.SelectedValue here
0
 
LVL 1

Author Comment

by:mlg101
ID: 34908562
I have populated the zones ddl via the code below. It is in the web method and not on the aspx page so I can't use the ddlzones.selectedvalue. I'm trying to get the selected value in the web method.
<WebMethod()> _
    Public Function GetTimeZone(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()



        Dim tzi As ReadOnlyCollection(Of TimeZoneInfo)
        tzi = TimeZoneInfo.GetSystemTimeZones()



        Dim myTimeZone As New List(Of CascadingDropDownNameValue)
        For Each timeZone As TimeZoneInfo In tzi
            Dim Zone As String = CStr(timeZone.DisplayName)
            Dim ZoneID As String = CStr(timeZone.Id)

            myTimeZone.Add(New CascadingDropDownNameValue(Zone, ZoneID))
            'End While
        Next timeZone
        Return myTimeZone.ToArray
    End Function

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34908735
You are returning TimeZoneInfo array in the method so it can be used. How do you bind it to the DDL?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:mlg101
ID: 34908895
Maybe I should just tell you what I want to do. I have 4 cascading ddls. Teacher, Instrument, Date, and Time (In that order). I have a 5th ddl, which is the time zone ddl. I want the Time to change depending on the time zone, but it is not dependent on the choices of the other 4, so it is really not cascading in that sense. I just don't know how to do the "converttimezone" function and have the correct time display in the "Time" ddl.

Maybe I could do it on the .aspx page instead of the .asmx page? But not sure because if I postback after changing the timezone ddl, it resets the 4 cascading ddls.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34909018
You have the code that converts the timezone. All you need now is the timezone to convert to. You can get it from the DDL but to convert, you need to timezoneid. So whether you do it in aspx or asmx, you need to get the selected timezone id from the DDL. Or you can get the select timezone (text) and then retrieve its ID.
0
 
LVL 1

Author Comment

by:mlg101
ID: 34909388
How do you stop the aspx page from resetting the cascading ddls on postback? You need to postback to get to convert as per the link you gave me
0
 
LVL 1

Author Comment

by:mlg101
ID: 34909471
I thought I was getting the timezone id in the asmx page by "intZoneID" below:

Dim strTimeName As String = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dtrTime("EventStart"), TimeZoneInfo.Local.Id, intZoneID.ToString()).ToString()
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34914543
>I thought I was getting the timezone id in the asmx page by "intZoneID" below
Are you passing it to the webservice?


>How do you stop the aspx page from resetting the cascading ddls on postback
Make sure the databinding code for the DDLs has this syntax

If Page.IsPostBack = False Then
   'Code to bind the DDLs
End If
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 35906841
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
grab and show facebook pages event calendars 6 46
Crystal Report for VS2013 17 42
VB.NET HttpWebRequest 12 34
Asp.net mvc 5 5 22
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now