I'm playing around with the calendar control and I can't seem to do the simple task of shading dates. If the user enters 7 dates I want to shade those dates on the calendar so the user knows they have been selected.
Essentially I want do Calendar.HighlightDate("5/1/11") => imaginary lol I know this must be simple but I'm gong through the properties on MSDN and not finding anything.
Set the ondayrender event of the calendar object:
<asp:Calendar ID="Calendar1" runat="server" ondayrender="MyDayRenderer">
Then in your code behind, you can check the date and set the color:
protected void MyDayRenderer(object sender, DayRenderEventArgs e)
{
if (e.Day.IsToday)
{
e.Cell.BackColor = System.Drawing.Color.Aqua;
}
if (e.Day.Date == new DateTime(2011,5,1))
{
e.Cell.BackColor = System.Drawing.Color.Beige;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With