if(e.Day.Date.DayOfWeek == DayOfWeek.Monday) { e.cell.BackColor=System.Drwaing.Color.Red; }
我正在尝试这个代码,但它只改变了一个月的属性,我想改变所有的DayOfweek在所有月份在一年中。
发布于 2013-12-30 05:58:30
您需要使用属性来设置所显示月份中日期的样式属性(包括颜色)。
此外,请注意,如果您没有为不在当前显示的月份中的日期指定不同的样式,则还将使用 DayStyle
属性指定的样式显示这些日期。
<asp:Calendar id="calendar1" runat="server">
<DayStyle BackColor="Red"></DayStyle>
</asp:Calendar>
如果您希望用不同的颜色显示其他月份的日期,请使用:
<asp:Calendar id="Calendar1" runat="server">
<OtherMonthDayStyle ForeColor="Green"></OtherMonthDayStyle>
</asp:Calendar>
最后,像往常一样,您也可以在代码中设置颜色属性。在本例中使用:事件。
void Calendar1_DayRender(Object sender, DayRenderEventArgs e)
{
// Change the background color of the days in other Months
// to yellow.
if (e.Day.IsOtherMonth)
{
e.Cell.BackColor=System.Drawing.Color.Yellow;
}
if (!e.Day.IsOtherMonth) // color to red for current month
{
e.Cell.BackColor=System.Drawing.Color.Red;
}
}
最后,在日历事件中导航月份时,使用:,用户每次更改月份时都会引发该事件。
标记::
<asp:Calendar ID="Calendar1"
OnVisibleMonthChanged="Calendar1_VisibleMonthChanged" />
代码::
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.Yellow;
Calendar1.DayStyle.BackColor = System.Drawing.Color.Red;
}
https://stackoverflow.com/questions/20833657
复制