I am using 2008 RAD Calendar Control. I do not want to show the Previous or Next month dates in Calendar. So I set the ShowOtherMonthsDays="false"
I also set FirstDayOfWeek="Monday".
I am getting Empty Row at the bottom if the first day starts from Tuesday to Friday. I was able to remove the Empty row from bottom by using some Server Side Logic.
Issue Starts here:
When the 1st day starts on Monday, I am getting one empty row on top of all the rows. I want to remove that row.
If I remove FirstDayOfWeek="Monday", then by default it takes FirstDayOfWeek="Sunday". So in this case I am getting an Extra Empty row on top of other rows if the First Day of week falls on Sunday.
Please help. I want to remove empty rows from Calendar.
FYI, I am using 6 Rows X 7 Colums Layout of Calendar.
Thanks,
Rakshit Bakshi
5 Answers, 1 is accepted
You can use the calendar DayRender server event and there depending on the first day of the current month to hide the top or the bottom empty row.
Please find attached a sample project with the suggested solution and let me know if this works for you.
Let us know how it goes.
Regards,
Iana
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Indeed, the desired functionality could be achieved for multi-month view calendar. In this case, you need perform a check for the first day of month not only for the FocusedDate month (which is date of the first month displayed) but for the other months in the multi-month view and hide the first empty row respectively.
I hope this helps.
Best wishes,
Iana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Write this code in ur calander render method. it will work cool.
CalendarDay
d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;
c.Controls.Add(
new LiteralControl("<br />2:00"));
if (d.IsOtherMonth && d.Date.Day>15)
{
if (d.Date.AddDays(6).Month == d.Date.Month && ViewState["count"]==null)
{
ViewState[
"count"] = 0;
}
if (Convert.ToInt16(ViewState["count"]) < 7 && ViewState["count"]!=null)
{
c.Text =
"";
ViewState[
"count"] = Convert.ToInt16(ViewState["count"]) + 1;
}
else
{
c.Text =
" ";
}
}
if (d.IsOtherMonth && d.Date.Day < 15)
{
if (d.Date.DayOfWeek.ToString() == "Sunday")
{
ViewState[
"next"] = "1";
}
if (Convert.ToString(ViewState["next"]) == "1")
{
c.Text =
"";
}
else
c.Text =
" ";
}
<telerik:RadCalendar runat="server" ID="RadCalendar2" |
OnDayRender="RadCalendar_DayRender" |
ShowOtherMonthsDays="false" /> |
Protected Sub RadCalendar_DayRender(ByVal sender As Object, ByVal e As Telerik.Web.UI.Calendar.DayRenderEventArgs) |
'' 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. |
Dim Cal As RadCalendar = CType(sender, RadCalendar) |
Dim currentMonth As Integer = Cal.FocusedDate.Month |
Dim FirstDay As Date = CDate(currentMonth & "/1/" & Cal.FocusedDate.Year) |
Dim LastDay As Date = FirstDay.AddDays(DateTime.DaysInMonth(FirstDay.Year, FirstDay.Month) - 1) |
If e.Day.Date < FirstDay OrElse e.Day.Date > LastDay Then |
Dim CurrentDayOfWeek As Int32 = CInt(e.Day.Date.DayOfWeek) |
Dim FirstDayOfWeek As Date = e.Day.Date.AddDays(CurrentDayOfWeek * -1) |
Dim LastDayOfWeek = FirstDayOfWeek.AddDays(6) |
If FirstDayOfWeek.Month <> currentMonth AndAlso LastDayOfWeek.Month <> currentMonth Then |
DirectCast((e.Cell.Parent), TableRow).Style("display") = "none" |
End If |
End If |
End Sub |
protected void RadCalendar_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; |
System.DateTime FirstDay = (System.DateTime)currentMonth + "/1/" + Cal.FocusedDate.Year; |
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; |
System.DateTime FirstDayOfWeek = e.Day.Date.AddDays(CurrentDayOfWeek * -1); |
object LastDayOfWeek = FirstDayOfWeek.AddDays(6); |
if (FirstDayOfWeek.Month != currentMonth && LastDayOfWeek.Month != currentMonth) { |
((TableRow)(e.Cell.Parent)).Style("display") = "none"; |
} |
} |
} |