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

Calendar Multi View Day Render

5 Answers 124 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
GDPR_erased
Top achievements
Rank 1
GDPR_erased asked on 28 Jul 2014, 06:51 PM
I'm trying to set up a yearly calendar and have a muti view of months 2X6, so all 12 months show, pretty simple.

 <telerik:RadCalendar ID="radCalendarYear" runat="server" MultiViewColumns="6" ShowRowHeaders="False"  MultiViewRows="2" 
         EnableNavigation="False" EnableMonthYearFastNavigation="false"
         UseColumnHeadersAsSelectors="false" ShowOtherMonthsDays="false" Width="99%">
    </telerik:RadCalendar>

Now, I want to run through the whole year and set the absent dates for the year. I want to replace the month day with an "E" for excused, and a "U" for Unexcused , and set the background color to red or yellow.

I looked at the Day render process, example, and it does what I want, but I cannot get it to work for a multiview. So, am i using the wrong method? Should I use the Special Days process instead? And if so, how would I replace the cell text in this process?

Could anyone help me with a subroutine example of looping through a datatable (or an iList), and setting the text and color of a multi-view calendar for the corresponding matching dates (calendar date to datatable date)?

Special days? or DayRender?

Thanks so much
,
~bg

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Jul 2014, 05:53 AM
Hi Bill,

Please try the below C# code snippet to achieve your scenario.

C#:
protected void radCalendarYear_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
{
    DateTime date1 = new DateTime(2014, 11, 10);
    DateTime date2 = new DateTime(2015, 1, 26);
    if(e.Day.Date.Equals(date1)||(e.Day.Date.Equals(date2)))
    {
        //based on the condition write code for style day
        e.Cell.Style["background-color"] = "Orange";
    }
}

Thanks,
Shinu.
0
GDPR_erased
Top achievements
Rank 1
answered on 29 Jul 2014, 06:24 PM
Thanks so much Shinu, but could I get one more pointer?
I have the property for the calendar: ShowOtherMonthsDays="false", so the dates do not show that carryover from month to month, however the day render's on both.. Please see the attached jpg. Is there something I can check so that the day that does not show will not be affected? I tried:
If e.Day.IsSelectable = True (only), that did not work.
If e.Cell.Text <> "", that did not work

I would like the February month not to show the red box. (It looks like a duplicate day visually.
Is that possible?
Thanks,
~bg
0
Shinu
Top achievements
Rank 2
answered on 30 Jul 2014, 02:49 AM
Hi Bill,

As a work around please try the below CSS code snippet which works fine at my end.

CSS:
.rcOtherMonth
{
    background-color : White !important;
}

Thanks,
Shinu.
0
GDPR_erased
Top achievements
Rank 1
answered on 30 Jul 2014, 12:03 PM
Thanks, but the problem with the style is that the background color dissapears (good), however, the text still remains. Rather than change the text to, (to white on white), I finnaly got this to work the best for anyone else who might want to know. Thanks Shinu for the help!
Protected Sub radCalendarYear_DayRender(sender As Object, e As Telerik.Web.UI.Calendar.DayRenderEventArgs) Handles radCalendarYear.DayRender
       Try
           For Each row As Data.DataRow In dt.Rows
               Dim IsInMonth As Boolean = e.Day.Date.Month = e.View.MonthStartDate.Month
               If e.Day.Date.Equals(CType(row.Item("CalendarDate").ToString, DateTime).Date) And IsInMonth Then
                   If row.Item("Excused").ToString = "E" Then
                       e.Cell.Style("background-color") = "Orange"
                   Else
                       e.Cell.Style("background-color") = "Red"
                   End If
                   e.Cell.Text = row.Item("ReasonCode").ToString
                   e.Cell.ToolTip = e.Day.Date & " " & row.Item("ReasonDescription").ToString
                   e.Cell.Style("text-align") = "center"
               End If
           Next
       Catch ex As Exception
           ucMessage.DisplayError(Utilities.GetErrorMessage(ex, "An error occurred: "))
       End Try
   End Sub
   Protected Function GetAttendanceDays() As DataTable
       Try
           Using db As New SqlConnection(ConfigurationManager.ConnectionStrings("XXXX").ConnectionString)
               Dim cmd As SqlCommand
               cmd = New SqlCommand("SP_Attendance", db)
               cmd.CommandType = CommandType.StoredProcedure
               cmd.Parameters.AddWithValue("@UserName", Page.User.Identity.Name)
               cmd.Parameters.AddWithValue("@XXXX", Request.QueryString("XXXX"))
               cmd.Parameters.AddWithValue("@AbsentTardy", "A")
               Using adapter As New SqlDataAdapter
                   adapter.SelectCommand = cmd
                   db.Open()
                   adapter.SelectCommand.CommandType = CommandType.StoredProcedure
                   Dim dt As New DataTable
                   adapter.Fill(dt)
                   Return dt
               End Using
           End Using
       Catch ex As Exception
           ucMessage.DisplayError(Utilities.GetErrorMessage(ex, "An error occurred: "))
           Return Nothing
       End Try
   End Function
0
Eyup
Telerik team
answered on 04 Aug 2014, 08:46 AM
Hi Bill,

I'm glad that you've managed to achieve the desired appearance.
If you want, you can also try accomplishing this task using programmatic special days as demonstrated in the attached sample.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Calendar
Asked by
GDPR_erased
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
GDPR_erased
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or