{
List<ScheduleEvent> lst;
public class ScheduleEvent
{
public string EventName;
public DateTime Date;
public Color EventColor;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//loading my list with some sample events.
lst = new List<ScheduleEvent>();
lst.Add(new ScheduleEvent {
Date = new DateTime(2011, 5, 17),
EventColor = Color.Lime,
EventName = "Arun's BirthDay" });
lst.Add(new ScheduleEvent {
Date = new DateTime(2011, 5, 31),
EventColor = Color.Red,
EventName = "Rohan's BirthDay" });
//Register day
Calendar1.DayRender += new DayRenderEventHandler(Calendar1_DayRender);
}
void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
var item=lst.Where(evnt => evnt.Date.Date.Equals(e.Day.Date)).FirstOrDefault();
if(item!=null)
{
e.Cell.BackColor = item.EventColor;
e.Cell.ToolTip = item.EventName;
e.Cell.Text = "<a href=" + e.SelectUrl + ">" + e.Day.DayNumberText + "</a>"; //調整滑鼠移到上方所顯示的內容
}
}
}
用此方式可以讓Asp行事曆裡面的元件更改你所紀錄日期的背景 底色 自體 或顯示的字樣
下列網址是Calendar屬性更改的參考網頁
http://msdn.microsoft.com/zh-tw/library/system.web.ui.webcontrols.calendar_properties.aspx
沒有留言:
張貼留言