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

Setting Color of Different Random Dates of RadCalender from Server Side

3 Answers 197 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Kamran
Top achievements
Rank 1
Kamran asked on 09 May 2013, 09:44 AM

 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

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 14 May 2013, 08:07 AM
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.
0
Kamran
Top achievements
Rank 1
answered on 16 May 2013, 01:27 PM
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 ?
0
Angel Petrov
Telerik team
answered on 21 May 2013, 05:15 PM
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.
Tags
Calendar
Asked by
Kamran
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Kamran
Top achievements
Rank 1
Share this question
or