日历控件 - 选中日期编程方式 [英] Calendar Control - Highlight Dates Programatically

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

问题描述

我在玩弄日历控件,我似乎无法做到遮阳日期简单的任务。如果用户输入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(11年5月1日)=>虚笑,我知道这一定是简单的,但我通过锣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 的日历对象的事件:

Set the ondayrender event of the calendar object:

<asp:Calendar ID="Calendar1" runat="server" ondayrender="MyDayRenderer">

然后在你的code的背后,你可以检查日期和设置颜色:

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天全站免登陆