日历控制 - 以编程方式突出显示日期

bum*_*una 4 c# asp.net calendar

我正在玩日历控件,我似乎无法完成着色日期的简单任务.如果用户输入7个日期,我想在日历上对这些日期进行着色,以便用户知道他们已被选中.

基本上我想做Calendar.HighlightDate("5/1/11")=>虚构大声笑我知道这一定很简单,但我通过MSDN上的属性并没有找到任何东西.

Dan*_*vay 5

设置日历对象的ondayrender事件:

<asp:Calendar ID="Calendar1" runat="server" ondayrender="MyDayRenderer">
Run Code Online (Sandbox Code Playgroud)

然后在您的代码后面,您可以检查日期并设置颜色:

   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;
        }
    }
Run Code Online (Sandbox Code Playgroud)