This is a migrated thread and some comments may be shown as answers.

Calendar Week Number Issue

3 Answers 49 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
RBarnes
Top achievements
Rank 1
RBarnes asked on 09 Apr 2019, 01:14 PM

Week 

Sunday: 12/30/2018 - Saturday: 01/05/2019 in SQL Server I get week #1

RadCalendar shows it as week 53.

I have this in my page load event,

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim C As System.Globalization.CultureInfo = New System.Globalization.CultureInfo(Me.rcCalendar.CultureInfo.ToString())
        C.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFourDayWeek
        C.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday
        Me.rcCalendar.CultureInfo = C

SQL server is using defaults, Set DateFirst 7 --Sunday

I've also tried this, nothing seems to make any change.

 Protected Overrides Sub InitializeCulture()
        Dim c As System.Globalization.CultureInfo = New System.Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString())
        c.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFourDayWeek
        System.Threading.Thread.CurrentThread.CurrentCulture = c
        MyBase.InitializeCulture()
    End Sub

 

I've also tried this Routine, which returns week #1 for date : 01/01/2019

Private Function GetIso8601WeekOfYear(ByVal pDateTime As DateTime) As Integer
        Dim day As DayOfWeek = Globalization.CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(pDateTime)
        If day >= DayOfWeek.Monday AndAlso day <= DayOfWeek.Wednesday Then
            pDateTime = pDateTime.AddDays(3)
        End If
        Return Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(pDateTime, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday)
    End Function

 

ASPX

<telerik:RadCalendar runat="server" ID="rcCalendar" EnableMultiSelect="False" Width="100%" Height="240px" FirstDayOfWeek="Sunday"
                        DayNameFormat="Short" AutoPostBack="True" ShowRowHeaders="true" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False"
                        EnableWeekends="True" FastNavigationNextText="&amp;lt;&amp;lt;" SelectedDate="" RangeSelectionMode="None">
                        <ClientEvents OnDateClick="DateClick" />
                    </telerik:RadCalendar>

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 12 Apr 2019, 12:41 PM

Hello,

Yes, you have found out the correct property to change this behavior. You can change with other options as well:
https://www.telerik.com/forums/handling-postback-in-dynamic-radcalendar#vlF_cz9OWE-I0HyBGa3LQw

This can be a Culture related issue. On my side I am getting the 12/30/2018 as week #1 with your exact definition - you can check the attached image.

I am also sending the sample I've used to test that.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
RBarnes
Top achievements
Rank 1
answered on 12 Apr 2019, 07:03 PM

Thanks for the sample, your sample in fact works as desired, it shows 1 for the week in question.

However, I have a slight alteration from the default behavior,

In the HeaderCellRender event, I'm getting the week #, and showing a total amount for the associated week of data from my DB, example week 1, instead of showing 1, I show $3,400 as an example

Add this to your example, you should now see 53 for the week in question, without the below it shows 1.  So it appears the value is changed somewhere after this event.

 Private Sub rcCalendar_HeaderCellRender(sender As Object, e As HeaderCellRenderEventArgs) Handles rcCalendar.HeaderCellRender
        Select Case e.HeaderType
            Case HeaderType.Row
                Dim Lbl As New Label
                Lbl.Text = e.Cell.Text
                e.Cell.Controls.Add(Lbl)
        End Select
    End Sub

 

 

0
Eyup
Telerik team
answered on 17 Apr 2019, 09:22 AM
Hi,

The calendar is not suitable to be used as a template container for server controls and server logic. This info will also be added in the following article:
https://docs.telerik.com/devtools/aspnet-ajax/controls/calendar/templates/header-and-footer-templates

In this case the week numbers are placed probably on the client, therefore, you will need to pass the values coming from database to client-side and set them using javascript. If you prefer, you can give me some examples how it should look like and I will prepare a runnable sample for you.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Calendar
Asked by
RBarnes
Top achievements
Rank 1
Answers by
Eyup
Telerik team
RBarnes
Top achievements
Rank 1
Share this question
or