Click here to Skip to main content
15,881,715 members
Articles / Web Development / ASP.NET

Event Calendar [ ASP.NET 2.0 / C# ]

Rate me:
Please Sign up or sign in to vote.
4.49/5 (62 votes)
18 May 2008CPOL4 min read 853.8K   38.7K   257   135
Basic Calendar Control of ASP.NET 2.0 can be extended to cater one of most frequent requirement of tracking events, project milestones, history, schedule etc.

Introduction

Tracking anything in dates is one of the common requirement now a days. Tracking events, project milestones, tracking history, tracking schedule etc etc. It was quite a complex job until the wonderful Calendar Control of ASP.NET 2.0. It is one of the Standard Server Side Web Control of ASP.NET 2.0, which when used properly can help in accomplishing the various requirements, tracking being one of them. Here we are going to see how can this Calendar control can help us in tracking the events.

Event Calendar 

One of best ways in which events can be displayed is by displaying the events by month. What it basically means is - display the complete month and display the events against each date. Here is how our Event Calendar is going to look like:

Screenshot - CalendarWithEventInColor.jpg

How can this be achieved  

It is quite simple and straight forward. ASP.NET Calendar control posses an event "DayRender" which has got "DayRenderEventArgs" as one of the parameters. This DayRenderEventArgs has got two very useful things - Day and Cell. Day is of the type "CalendarDay" and Cell is of the type "TableCell". Day can help us in identifying the day, date etc which it is going to render and Cell gives us handle to the table cell corresponding to that day. Now since we have handle to Table Cell of displaying Date, we can play with it to cater to our needs. For event Calendar we are simply going to use this event to add the event details in the Table Cells associated with the dates.

C#
CalendarDay d = ((DayRenderEventArgs)e).Day;
TableCell c = ((DayRenderEventArgs)e).Cell;

if ( !d.IsOtherMonth )
    c.Controls.Add(new LiteralControl(dr["EventDetails"].ToString()));

And thats it, we are done.

Event Calendar Control

If we are aware that we are going to use the same functionality again and again, it is better to make it a re-usable component. So here, we are going to extend the capabilities of basic ASP.NET 2.0 Calendar control. The basic requirement of data driven applications is that source of information basically is data store. It can be database, XML File, Excel or anything for that matter. Here we are going to limit our scope and going to implement the EventCalendar with ADO.NET DataTable as the source of data. Let us see the ingredients of this calendar control

  1. A class which extends System.Web.UI.WebControls.Calendar
  2. The necessary properties:

    • EventSource: DataTable with Event Details
    • EventStartDateColumnName: ColumnName of the Column of the type DateTime in the EventSource, which stores the Start Date associated with Events
    • EventEndDateColumnName: ColumnName of the Column of the type DateTime in the EventSource, which stores the End Date associated with Events
    • EventHeaderColumnName: ColumnName of the Column of the type String in the EventSource, which stores the Event Header,
    • EventDescriptionColumnName: ColumnName of the Column of the type String in the EventSource, which stores the Event Detailed Description,
    • ShowDescriptionAsToolTip: Boolean to determine whether to display Event Description as Tool Tip or not.
    • EventForeColor: ColumnName of the Column to specify the Fore ( Font ) Color for the event. We can specify any Color Name which belongs to System.Drawing.Color namespace.
    • EventBackColor: ColumnName of the Column to specify the Back Color for the event.We can specify any Color Name which belongs to System.Drawing.Color namespace.
  3. EventCalendarDayRender Event: Place where the actual logic to show the events in Calendar is implemented

This describes the skeleton for your EventCalendar Class. Refer to the EventCalendar.cs class file in the attached demo for complete implementation. By extending the control in such way we can keep the basic features provided along with the new features/capabilities that we need to cater to our requirements.

Version History

Version 3 

Support for Fore and Back Color for Events has been added. Click here to download its demo

Version 2

Support for Events which spills over more that one days has been added. Click here to download its demo

Version 1

Basic Event Calendar with support for Events which occurs on a single date Click here to download its demo

Wrapping Up

ASP.NET Controls are undergoing development and continuous evolution with each release, ASP.NET 2.0 Controls are no exception. These controls not only getting smarter and smarter, but also giving a developer better handle to its basic buidling blocks like TableCell of Calendar Control.

Please spare some time to rate and provide feedback about this article. Your couple of minutes can help in enhancing the quality of this article.

If interested, Click here to view all my published articles.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
.NET Professional, working with a leading global firm.

Primarily works in .NET using C# with Oracle and MS SQL Server 2000 as backend.

Learning .Net ...

[ My Linked In Profile ^ ]

Comments and Discussions

 
GeneralGreat Article Pin
joshc27-Mar-08 0:01
joshc27-Mar-08 0:01 
GeneralGreat Article Pin
Majid Malik26-Mar-08 23:57
Majid Malik26-Mar-08 23:57 
GeneralPopUp on Mouse Over Pin
Govardhana Reddy28-Feb-08 3:30
professionalGovardhana Reddy28-Feb-08 3:30 
GeneralGetting Error setting the Event Calendar up... Pin
johninkum2@yourehelp.com25-Feb-08 16:46
johninkum2@yourehelp.com25-Feb-08 16:46 
GeneralRe: Getting Error setting the Event Calendar up... Pin
Neeraj Saluja25-Feb-08 20:34
Neeraj Saluja25-Feb-08 20:34 
QuestionHoverMenuExtender [modified] Pin
NickKa17-Dec-07 4:39
NickKa17-Dec-07 4:39 
GeneralRe: HoverMenuExtender Pin
NickKa17-Dec-07 12:10
NickKa17-Dec-07 12:10 
GeneralDo you have VB version Pin
dfourlive16-Oct-07 10:04
dfourlive16-Oct-07 10:04 
Generaldefault.aspx.vb Pin
jadams_WCG5-Mar-08 10:12
jadams_WCG5-Mar-08 10:12 
GeneralHi Pin
CharlP1-Oct-07 21:16
CharlP1-Oct-07 21:16 
GeneralVery nice Pin
Pete O'Hanlon31-Aug-07 4:08
mvePete O'Hanlon31-Aug-07 4:08 
GeneralVery Cool Pin
merlin98131-Aug-07 3:59
professionalmerlin98131-Aug-07 3:59 
Generalgood job! Pin
The One And Only Ngel16-Aug-07 8:15
The One And Only Ngel16-Aug-07 8:15 
QuestionHow to add mouse hover in ASP.Net 2.0 calendar control Pin
Vipin Narayane29-Jul-07 18:49
Vipin Narayane29-Jul-07 18:49 
Generalhttp://slmhi.info/Calendar/tabid/620/Default.aspx Pin
yi_huangyi_yi_new@hotmail.com10-Jul-07 3:53
yi_huangyi_yi_new@hotmail.com10-Jul-07 3:53 
GeneralMaking cell updatable Pin
sharma sanjeev7-Jun-07 23:54
sharma sanjeev7-Jun-07 23:54 
GeneralRe: How can we generate summary Pin
Neeraj Saluja5-Jun-07 7:43
Neeraj Saluja5-Jun-07 7:43 
GeneralFirst date displayed and last date displayed Pin
ljunquera30-May-07 9:12
ljunquera30-May-07 9:12 
GeneralRe: First date displayed and last date displayed Pin
Gralov29-Nov-07 2:59
Gralov29-Nov-07 2:59 
QuestionNice Pin
sides_dale19-May-07 11:19
sides_dale19-May-07 11:19 
QuestionEnable html to tooltip? Pin
cherylng9-May-07 11:21
cherylng9-May-07 11:21 
AnswerRe: Enable html to tooltip? Pin
Neeraj Saluja13-May-07 9:24
Neeraj Saluja13-May-07 9:24 
Generalgiving each event a different color Pin
ranine16-Apr-07 21:49
ranine16-Apr-07 21:49 
GeneralRe: giving each event a different color Pin
Neeraj Saluja17-Apr-07 0:02
Neeraj Saluja17-Apr-07 0:02 
GeneralRe: giving each event a different color Pin
ranine17-Apr-07 0:38
ranine17-Apr-07 0:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.