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

时间:2011-12-18 11:16:21

标签: asp.net vb.net calendar

我的网络表单上有一个ASP.NET Calendar控件。

我已经使用StartDateEndDate定义了一个日期范围,现在我需要让它们之间的所有日期(包括StartDateEndDate)红色

我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

您可以处理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即可将日期与自定义范围进行比较,并将背景颜色从黄色更改为红色。