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

RadCalendar : Show 5 weeks instead of 6

4 Answers 51 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Erwan
Top achievements
Rank 1
Erwan asked on 22 Aug 2012, 10:07 AM
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

4 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 22 Aug 2012, 01:10 PM
Hello Erwan,

You can set the ShowOtherMonthsDays="false" property.

I hope that helps.
0
Erwan
Top achievements
Rank 1
answered on 22 Aug 2012, 01:17 PM
Hello Kevin,

the result is not the one I expected....
The ShowOtherMonthsDays="false" property, just had a blank cell
0
Accepted
Princy
Top achievements
Rank 1
answered on 23 Aug 2012, 05:51 AM
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.
0
Erwan
Top achievements
Rank 1
answered on 23 Aug 2012, 09:04 AM
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
Tags
Calendar
Asked by
Erwan
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Erwan
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or