How to mark the event in the calendar control?

Posted by Laghaterohan under ASP.NET on 5/14/2011 | Points: 10 | Views : 4549 | Status : [Member] | Replies : 2
Hello,

I have some events schedule each month. For scheduling a event a user can directly enter a date and schedule it and confirm it.
In my calendar control i want the dates for which the events were scheduled to be marked in some color. So that when i see view dates in calendar control
i get to know directly on which date the events were schedule....how can i do this???


Thanks !

Best Regards,
Rohan Laghate



Responses

Posted by: Ndebata on: 5/16/2011 [Member] Starter | Points: 25

Up
0
Down
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

Posted by: Laghaterohan on: 5/17/2011 [Member] Starter | Points: 25

Up
0
Down
Hey Thanks Debata,

However i am using th AJAX Calendar and not ASP.NET calendar control....So i dont get Day Render event...

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response