Solved

Change time zone in Cascading DropDown

Posted on 2011-02-15
13
519 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
edit .asp files 5 31
Add or delete table rows 10 54
Can Angular be used with classic asp.net? 3 17
How to filter by key press ? 6 23
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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