使用 Visual Studio for web 2012 中的日历控件,我可以从 SQL Server 2012 数据库中获取日期(即到日期和开始日期并在日历中突出显示此日期)我还可以突出显示两者之间的日期to date和from date。
总而言之,在我的日历中,我在日历中突出显示了日期 02/10/2013(至今)和 04/10/2013(从日期开始)以及这些日期之间的日期。并且还突出显示 2013 年 10 月 15 日(至今)和 2013 年 10 月 19 日(从日期开始),并突出显示这些日期之间的日期。
但是我希望能够随机更改日历中每个选定日期块的背景颜色?我该怎么做呢?
非常感谢
这是一些代码,用背景颜色突出显示日期并使其可选择等。这段代码工作得很好,但我希望能够做到以上几点?
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (dsHolidays != null)
{
foreach (DataRow dr in dsHolidays.Tables[0].Rows)
{
DateTime nextDate;
DateTime endDate;
nextDate = (DateTime)dr["date"];
endDate = (DateTime)dr["date1"];
if (nextDate <= e.Day.Date && endDate >= e.Day.Date)
{
e.Cell.BackColor = System.Drawing.Color.Gray;
// dates are unselectable
e.Day.IsSelectable = false;
}
}
}
// makes the all the first dates selectable
foreach (DataRow dr in dsHolidays.Tables[0].Rows)
{
DateTime nextDate1;
nextDate1 = (DateTime)dr["date"];
{
if (e.Day.Date == nextDate1)
{
e.Day.IsSelectable = true;
e.Cell.ForeColor = System.Drawing.Color.Blue;
}
}
}
}