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

OnDayRender not changing background color until month is changed.

1 Answer 92 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 26 May 2016, 01:57 PM

I am changing the background color of a date ( that is being provided from the database ) by using the Calendar OnDayRender.  The problem is that when the page initially loads the background color is not present.  But if I change the month, then go back to the previous month, the background color appears.

 

ASP:

<telerik:RadDatePicker AutoPostBack="true" OnSelectedDateChanged="rdpEnd_SelectedDateChanged" ID="rdpEnd" ToolTip="" class="form-control" Style="width: 100%;" Height="30px" aria-describedby="ptoEndDate" runat="server">
 
<DatePopupButton ToolTip="" />
<Calendar runat="server" ShowRowHeaders="false" OnDayRender="CustomizeDay">
 
</Calendar>
</telerik:RadDatePicker>

 

C#

protected void CustomizeDay(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e)
{
  DateTime CurrentDate = e.Day.Date;
  using (DataClassesDataContext db = new DataClassesDataContext())
  {
    if(db.Calendars.Where(x => x.date.Value.Date == e.Day.Date).Any())
      {
       TableCell currentCell = e.Cell;
       currentCell.Style["background-color"] = "#000000";
      }
   }
}

   

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 31 May 2016, 07:58 AM
Hi Sean,

In order to customize some dates in the DatePicker you need to handle the DayRender events on the server and on the client. Check out the following code-library that illustrates similar scenario.



Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
DatePicker
Asked by
Sean
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or