Solved

Change time zone in Cascading DropDown

Posted on 2011-02-15
13
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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