System.Web.UI.WebControls.Calendar是否可以更改单个选择的颜色?

时间:2009-03-28 03:55:31

标签: asp.net controls calendar

我有代码在日历控件中进行多项选择,但我想将最初选择的日期的颜色更改为绿色,将结束日期更改为红色。在视觉上,这将指示某个服务的开始日期和结束日期 提供。我应该查看我的calander的RenderControl方法还是更多考虑设置控件中几天的属性?

多选代码可归因于 Steve Wellins

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        System.Web.UI.WebControls.Calendar TheCalendar = sender as System.Web.UI.WebControls.Calendar;

        // create new list of dates or get stored list of dates
        List SelectedDates;

        if (ViewState["SelectedDates"] == null)
            SelectedDates = new List();
        else
            SelectedDates = ViewState["SelectedDates"] as List;

        // if date is already in list, remove it, otherwise, add it
        if (SelectedDates.Contains(TheCalendar.SelectedDate) == false)
            SelectedDates.Add(Calendar1.SelectedDate);
        else
            SelectedDates.Remove(Calendar1.SelectedDate);

        // set the calendar to our list of dates
        TheCalendar.SelectedDates.Clear();
        foreach (DateTime Date in SelectedDates)
            TheCalendar.SelectedDates.Add(Date);

        // store list for next postback
        ViewState["SelectedDates"] = SelectedDates;
    }

此代码可能会覆盖应用于日历的任何日期或格式,但我不会保存并将此格式恢复到日历。


foreach (DateTime Date in SelectedDates)
                TheCalendar.SelectedDates.Add(Date);

如果您指出正确的路径或要搜索的条款,我很乐意研究潜在客户。

1 个答案:

答案 0 :(得分:0)

在MSDN网站上,每天渲染时都会调用Calendar .. ::。OnDayRender方法。我是一个.NET noob ...如何使用它?