Hi
You can use DayRender event of Asp.Net Calendar control.
in aspx page
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</div>
</form>
in code behind page I have created a class that will describe the schedule event.
public class ScheduleEvent
{
public string EventName{ get; set; }
public DateTime Date { get; set; }
public Color EventColor { get; set; }
}
Now OnPage load event I am registering the day render where I will check if any event is there on a day for a month shown in calendar, I am changing the background color and showing the event name as tooltip.
public partial class TestPage : System.Web.UI.Page
{
List<ScheduleEvent> lst;
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;
}
}
}
* Please feel free to modify to accomodate your requirements. :)
Thanks,
Debata
Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator