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

Empty Rows at the Top

5 Answers 148 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Rakshit
Top achievements
Rank 1
Rakshit asked on 15 Jul 2008, 02:26 AM
Telerik,

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

Sort by
0
Iana Tsolova
Telerik team
answered on 17 Jul 2008, 02:55 PM
Hello Rakshit,

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
0
Dave
Top achievements
Rank 1
answered on 24 Jun 2009, 09:04 PM
This works for SingleView calendars, but how would I do this for Multiview calendars?
0
Iana Tsolova
Telerik team
answered on 29 Jun 2009, 11:15 AM
Hi Dave,

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.
0
Ram Prabu
Top achievements
Rank 1
answered on 20 Jul 2009, 11:33 AM

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 =

"&nbsp;";

 

}

}

 

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 =

"&nbsp;";

 

}

0
John Snyder
Top achievements
Rank 1
answered on 15 Jan 2010, 03:24 PM
The logic from the sample project provided by Telerik did not seem to work correctly for me.  There were some months that still showed the empty row.  It was also using the focused date when it should of been using the first day of the month which may not have been the first day of the month which ultimately caused even more issues such as a week in the middle of the month being hidden.

I wanted to share my code that seems to work with the rest of the community.  Note that I did not test the C# but instead used Telerik's converter to get the code:

HTML
<telerik:RadCalendar runat="server" ID="RadCalendar2"  
     OnDayRender="RadCalendar_DayRender"  
     ShowOtherMonthsDays="false" /> 

VB.Net
    Protected Sub RadCalendar_DayRender(ByVal sender As ObjectByVal 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 

C#
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"
        } 
    } 

FYI - I am using the Telerik Q3 2009 controls but the logic here should work either way.

Hope this helps someone out
Tags
Calendar
Asked by
Rakshit
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Dave
Top achievements
Rank 1
Ram Prabu
Top achievements
Rank 1
John Snyder
Top achievements
Rank 1
Share this question
or