Solved

Change time zone in Cascading DropDown

Posted on 2011-02-15
13
518 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert html to string 6 34
Help with exporting to excel 4 27
RLDC Reporting in Visual studio 11 16
vb.net 1 month apart 11 29
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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