Setting Color of Different Random Dates of RadCalender from Server Side

4 posts, 0 answers
  1. Kamran
    Kamran avatar
    11 posts
    Member since:
    Apr 2012

    Posted 09 May 2013 Link to this post

     have a Rad Calender. I have to apply some code logic with database and If my code logic gives me FALSE for a particular selected date of Rad Calender than I have to show that Date in RED color of that Rad Calender. In other words I have to set RED color for different dates of Rad Calender through Server Side.

    For a brief view I am attaching some Screen shots that will elaborate my Scenrio

    1- http://screencast.com/t/LJUhqaLM
    2- http://screencast.com/t/BOPDNNMJuh

    Any Help ?

    Regards: Kamran

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 14 May 2013 Link to this post

    Hello Kamran,

    In order to meet your requirements you can intercept the OnDayRender event of the calendar, check whether the date should be styled and if so assign a CSS class. An example of this is shown in the code snippets below:

    ASPX
    <html>
    <head>
        <title>Test</title>
        <script type="text/javascript">
        </script>
        <style type="text/css">
            td.MyCellStyle
            {
                background-color:green;
            }
        </style>
    </head>
    <body>
        <form id="Form1" runat="server">
         <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
        <telerik:RadCalendar ID="Calendar1" OnDayRender="Calendar1_DayRender" runat="server"></telerik:RadCalendar>
        </form>
    </body>
    </html>

    C#
    protected void Calendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
       {
           if(e.Day.Date.Day==15)
           {
               e.Cell.CssClass = "MyCellStyle";
           }
       }

    Kind regards,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kamran
    Kamran avatar
    11 posts
    Member since:
    Apr 2012

    Posted 16 May 2013 Link to this post

    Hi Angel Petrov 
    , Thanks for Replying Me

    Your proposed solution is quite good but It did not meet my desired requirements.
    Have a look on my code plz.

     while (RadCalender1.SelectedDate <= DateTime.Now.AddDays(10))
         {
    //This is my code logic against RadCalender Selected Date
                            bool IsAvailable= GetByDateFromDB(RadCalender1.SelectedDate);
             if (! IsAvailable)
                            {
                                // Here I need to change the ForeColor of this Selected date to RED and also I need to make this  Date Disabled
                            }
                            RadCalender1.SelectedDate = RadCalender1.SelectedDate.AddDays(1);
          }
    Now you can see that If IsAvailable is false against RadCalender selected date than I have to make that Date as Disabled and its ForeColor should be RED.

    Can It possible to do this ?
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 21 May 2013 Link to this post

    Hello Kamran,

    I am sorry to say but you can not modify the dates outside the OnDayRender event. That said I suggest that you modify the code-logic like demonstrated below:

    C#:
    protected void Calendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
       {
           if (e.Day.Date >= Calendar1.SelectedDate && e.Day.Date <= DateTime.Now.AddDays(10))
           {
               bool IsAvailable = GetByDateFromDB(e.Day);
               if (!IsAvailable)
               {
                   e.Cell.CssClass = "MyCellStyle";
                   e.Day.IsDisabled = true;
               }
           }
       }

    Another option would be to use the SpecialDays collection like demonstrated it this code library.

    All the best,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top