RadCalendar : Show 5 weeks instead of 6

5 posts, 1 answers
  1. Erwan
    Erwan avatar
    3 posts
    Member since:
    Aug 2012

    Posted 22 Aug 2012 Link to this post

    Hello,

    In some months as August 2012, 6 weeks are shown but the last row contains only days of September.
    In this case, is it possible to suppress the last row?

    Regards,

    Erwan
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 22 Aug 2012 Link to this post

    Hello Erwan,

    You can set the ShowOtherMonthsDays="false" property.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Erwan
    Erwan avatar
    3 posts
    Member since:
    Aug 2012

    Posted 22 Aug 2012 Link to this post

    Hello Kevin,

    the result is not the one I expected....
    The ShowOtherMonthsDays="false" property, just had a blank cell
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Aug 2012 Link to this post

    Hi Erwan,

    Try the following code to achieve your scenario.

    ASPX:
    <telerik:RadCalendar ID="RadCalendar1" runat="server" ondayrender="RadCalendar1_DayRender"  AutoPostBack="true" >
    </telerik:RadCalendar>

    C#:
    protected void RadCalendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
        {
            //' This method is used to hide the empty rows at the top/bottom that show up when the month starts on a Sunday or ends on a Saturday.
            RadCalendar Cal = (RadCalendar)sender;
            int currentMonth = Cal.FocusedDate.Month;
            DateTime FirstDay = new DateTime(Cal.FocusedDate.Year, currentMonth, 1);
            System.DateTime LastDay = FirstDay.AddDays(DateTime.DaysInMonth(FirstDay.Year, FirstDay.Month) - 1);
     
            if (e.Day.Date < FirstDay || e.Day.Date > LastDay)
            {
                Int32 CurrentDayOfWeek = (int)e.Day.Date.DayOfWeek;
                DateTime FirstDayOfWeek = e.Day.Date.AddDays(CurrentDayOfWeek * -1);
                DateTime LastDayOfWeek = FirstDayOfWeek.AddDays(6);
                if (FirstDayOfWeek.Month != currentMonth && LastDayOfWeek.Month != currentMonth)
                {
                    ((TableRow)(e.Cell.Parent)).CssClass = "rchidden";
     
                }
            }
    }

    Hope this helps.

    Thanks,
    Princy.
  6. Erwan
    Erwan avatar
    3 posts
    Member since:
    Aug 2012

    Posted 23 Aug 2012 Link to this post

    Hi Princy,

    Your code worked well.
    I just had to adapt it in the french way ;)
    (The first day of the week is monday and the last is sunday.)

    here is the code (in VB) :

    Dim cal As RadCalendar = CType(sender, RadCalendar)
    Dim currentMonth As Integer = cal.FocusedDate.Month
    Dim firstDay As DateTime = New DateTime(cal.FocusedDate.Year, currentMonth, 1)
     
    Dim lastDay As System.DateTime = firstDay.AddDays(DateTime.DaysInMonth(firstDay.Year, firstDay.Month) - 1)
     
     
    If (e.Day.Date < firstDay Or e.Day.Date > lastDay) Then
     
        Dim CurrentDayOfWeek As Int32 = CInt(e.Day.Date.DayOfWeek)
        'If Sunday, we set CurrentDayOfWeek to 7 instead of 0
        If CurrentDayOfWeek = 0 Then CurrentDayOfWeek = 7
        Dim FirstDayOfWeek As DateTime = e.Day.Date.AddDays((CurrentDayOfWeek * -1) + 1)
        Dim LastDayOfWeek As DateTime = FirstDayOfWeek.AddDays(6)
        If (Not FirstDayOfWeek.Month = currentMonth And Not LastDayOfWeek.Month = currentMonth) Then
            e.Cell.Text = ""
            CType(e.Cell.Parent, TableRow).CssClass = "rchidden"
        End If
    End If


    Thank you very much.

    Erwan
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017