How to customize display of dates in Calendar control

This is a quick tip on how you can customize display of individual dates on ASP.Net calendar control. The control provides an event for DayRender. You just need to handle it and then manipulate underlying Cell element for that date. The following code snippet shows how I assigned style for alternate days. You can use the same concept to style your important dates differently.

protected void OnCalendarDayRender(object sender, DayRenderEventArgs e)
{
 if (e.Day.Date.Day % 2 == 0)
 {
   e.Cell.CssClass = "importantdate";
 }
}

.importantdate
{
    color:#ff0000;
    background-color:#555;
    font-weight:bold;
    border:1px dotted #ff00ff;
}
comments powered by Disqus

Blog Tags