在日历控件上自定义日期范围的外观

问题描述:

我的web表单上有一个ASP.NET Calendar控件。在日历控件上自定义日期范围的外观

我已经定义的日期范围与StartDateEndDate,现在我需要做的所有天之间(包括StartDateEndDate)红色。

我该怎么做?

您可以处理Calendar.DayRender事件并自定义日期范围内单元格的外观。一个完整的例子是MSDN文档页面上,但最重要的部分是:

Sub DayRender(source As Object, e As DayRenderEventArgs) 
    ' Change the background color of the days in the month to yellow. 
    If Not e.Day.IsOtherMonth And Not e.Day.IsWeekend Then 
     e.Cell.BackColor = System.Drawing.Color.Yellow 
    End If 
End Sub 'DayRender 

你只需要适应If一天来比较您的自定义范围,改变从黄色的背景颜色为红色。