C# 在calendar asp.net C中随机更改选定日期的背景色#

C# 在calendar asp.net C中随机更改选定日期的背景色#,c#,asp.net,sql-server-2012,C#,Asp.net,Sql Server 2012,使用Visual Studio for web 2012中的日历控件,我可以从SQL Server 2012数据库中提取日期(即到日期和从日期并在日历中突出显示此日期),我还可以突出显示从日期到日期和从日期之间的日期 总而言之,在我的日历中,我在日历中突出显示了2013年10月2日(截止日期)和2013年10月4日(起始日期),以及这些日期之间的日期。还突出显示了2013年10月15日(截止日期)和2013年10月19日(起始日期),并突出显示了这些日期之间的日期 但是,我希望能够随机更改日历中

使用Visual Studio for web 2012中的日历控件,我可以从SQL Server 2012数据库中提取日期(即到日期从日期并在日历中突出显示此日期),我还可以突出显示从日期到日期和从日期之间的日期

总而言之,在我的日历中,我在日历中突出显示了2013年10月2日(截止日期)和2013年10月4日(起始日期),以及这些日期之间的日期。还突出显示了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;

            }
        }
    }

}
受保护的无效日历1\u DayRender(对象发送方,DayRenderReventArgs e)
{
if(dsHolidays!=null)
{
foreach(dsHolidays.Tables[0]中的DataRow dr.行)
{
日期时间下一个日期;
日期时间结束日期;
下一个日期=(日期时间)dr[“日期”];
endDate=(DateTime)dr[“date1”];
如果(下一个日期=e.Day.Date)
{
e、 Cell.BackColor=System.Drawing.Color.Gray;
//日期不可选择
e、 Day.IsSelectable=假;
}
}
}
//使所有第一个日期都可选择
foreach(dsHolidays.Tables[0]中的DataRow dr.行)
{
日期时间下一个日期1;
nextDate1=(日期时间)dr[“日期”];
{
如果(e.Day.Date==nextDate1)
{
e、 Day.IsSelectable=true;
e、 Cell.ForeColor=System.Drawing.Color.Blue;
}
}
}
}

也许这段代码会有所帮助

Random randomGen = new Random();
KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));
Color newColor = Color.FromKnownColor(names[randomGen.Next(names.Length)]);

如何使用上面添加的代码添加此代码。坦克斯
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{

    if (e.Day.IsWeekend)
    {
        e.Day.IsSelectable = false;
        e.Cell.BackColor = System.Drawing.Color.Yellow;
    }

    if(e.Day.Date.Day%2==0 && !e.Day.IsOtherMonth && !e.Day.IsWeekend)
    {
        e.Day.IsSelectable = false;
        e.Cell.BackColor = System.Drawing.Color.Orange;
        e.Cell.ToolTip = "Booked";

    }
    if (e.Day.Date.Day % 2 != 0 && !e.Day.IsOtherMonth && !e.Day.IsWeekend)
    {
        e.Day.IsSelectable = false;
        e.Cell.BackColor = System.Drawing.Color.PaleGreen;
        e.Cell.ToolTip = "Available";
    }
    if(e.Day.Date.Day%5==0 && !e.Day.IsOtherMonth && !e.Day.IsWeekend )
    {
        e.Day.IsSelectable = false;
        e.Cell.BackColor = System.Drawing.Color.Green;
        e.Cell.ToolTip = "Fast Booking";
    }
}