日历控件-以编程方式突出显示日期 [英] Calendar Control - Highlight Dates Programmatically

查看:84
本文介绍了日历控件-以编程方式突出显示日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用日历控件,但似乎没有完成简单的为日期加阴影的任务。如果用户输入7个日期,则我想在日历上为这些日期加阴影,以便用户知道它们已被选中。

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.

本质上,我想做Calendar.HighlightDate( 5 / 1/11)=>想象中的笑声,我知道这很简单,但是我在MSDN上仔细研究了属性,但没有找到任何东西。

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.

推荐答案

设置日历对象的 ondayrender 事件:

<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;
        }
    }

这篇关于日历控件-以编程方式突出显示日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆