如何在ASP.NET/C#上给日历上色
本文关键字:日历 ASP NET | 更新日期: 2023-09-27 18:12:30
我在使用ASP。. NET, c#编程,Visual Studio 2010。
我有一个日历,日期必须用员工输入的数据填写,数据将进入我的数据库。
每天有8个小时,我想:
If the day is empty, with 0 hours filled, colored red on
If the day is half-filled, with 1-7 hours filled, colored yellow on
If the day is full, with 8 hours filled, colored green on
我希望我解释的正确,这是我的代码:
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
ShowGridLines="True" Width="1500px"
OnSelectionChanged="Calendar1_SelectionChanged"
OnDayRender = "Calendar1_DayRender">
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
和c#:
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
Style ImputedDaysStyle = new Style();
ImputedDaysStyle.BackColor = System.Drawing.Color.Green;
ImputedDaysStyle.BorderColor = System.Drawing.Color.Purple;
ImputedDaysStyle.BorderWidth = 1;
Style HalfImputedDaysStyle = new Style();
ImputedDaysStyle.BackColor = System.Drawing.Color.GreenYellow;
ImputedDaysStyle.BorderColor = System.Drawing.Color.Purple;
ImputedDaysStyle.BorderWidth = 1;
if (e.Day.Date.Month.ToString() != SelectedMonth) return;
if (HoursXDayInMonth[e.Day.Date.Day-1] >= 8) e.Cell.ApplyStyle(ImputedDaysStyle);
else if (HoursXDayInMonth[e.Day.Date.Day - 1] >= 1) e.Cell.ApplyStyle(HalfImputedDaysStyle);
}
如果有人知道怎么做,请告诉我!谢谢!
如果您需要突出显示日历中的特定列
那么你可以看看这个链接:http://www.codeproject.com/Articles/7929/Highlighting-Important-Dates-in-Calendar