Calendar Multi View Day Render

6 posts, 0 answers
  1. Bill
    Bill avatar
    94 posts
    Member since:
    Aug 2006

    Posted 28 Jul 2014 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2014 in reply to Bill Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bill
    Bill avatar
    94 posts
    Member since:
    Aug 2006

    Posted 29 Jul 2014 in reply to Shinu Link to this post

    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
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2014 in reply to Bill Link to this post

    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.
  6. Bill
    Bill avatar
    94 posts
    Member since:
    Aug 2006

    Posted 30 Jul 2014 in reply to Shinu Link to this post

    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
  7. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 04 Aug 2014 Link to this post

    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.

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