Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar Control - Highlight Dates Programmatically

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.

like image 407
bumble_bee_tuna Avatar asked Feb 24 '23 09:02

bumble_bee_tuna


1 Answers

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;
        }
    }
like image 84
Dan Solovay Avatar answered Mar 08 '23 23:03

Dan Solovay