Click here to Skip to main content
11,430,274 members (77,112 online)
Click here to Skip to main content

Event Calendar [ ASP.NET 2.0 / C# ]

, 19 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

        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)

Share

About the Author

Neeraj Saluja
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

 
GeneralClickable cell Pin
CloudWebi25-Jul-14 7:15
memberCloudWebi25-Jul-14 7:15 
Questionhelpful Pin
Member 108982049-Jul-14 19:43
memberMember 108982049-Jul-14 19:43 
QuestionGetting an error when trying to create in VB.NET Pin
russell_bolosan@tempe.gov13-Jun-13 10:21
memberrussell_bolosan@tempe.gov13-Jun-13 10:21 
QuestionDesign - Look and Feel of Calendar Pin
Neha wahi11-Jun-13 18:56
memberNeha wahi11-Jun-13 18:56 
AnswerRe: Design - Look and Feel of Calendar Pin
Neeraj Saluja11-Jun-13 19:58
memberNeeraj Saluja11-Jun-13 19:58 
GeneralRe: Design - Look and Feel of Calendar Pin
Neha wahi11-Jun-13 20:28
memberNeha wahi11-Jun-13 20:28 
QuestionRecurring Events Pin
Neha wahi11-Jun-13 0:44
memberNeha wahi11-Jun-13 0:44 
AnswerRe: Recurring Events Pin
Neeraj Saluja11-Jun-13 6:26
memberNeeraj Saluja11-Jun-13 6:26 
GeneralRe: Recurring Events Pin
Neha wahi11-Jun-13 18:54
memberNeha wahi11-Jun-13 18:54 
Questionconsulta necesito controlar el tamaño del control eventcalendar Pin
diana ysabel3-Jan-13 11:25
memberdiana ysabel3-Jan-13 11:25 
QuestionNeed to display single event in multiple cells Pin
Member 806441714-Nov-12 17:51
memberMember 806441714-Nov-12 17:51 
QuestionNeed to display single event in multiple cells Pin
Member 47683617-Nov-12 5:17
memberMember 47683617-Nov-12 5:17 
Instead of showing events in 3 days can I show the events that stretch from 18th to 20th like outlook
GeneralEvents on the same day [modified] Pin
Member 23788889-Aug-12 3:28
memberMember 23788889-Aug-12 3:28 
GeneralRe: Events on the same day Pin
Member 1136870115-Apr-15 1:31
memberMember 1136870115-Apr-15 1:31 
GeneralSee also DayPilot (Day/Week/Resources View) Pin
Dan Letecky19-Jun-12 11:36
memberDan Letecky19-Jun-12 11:36 
QuestionAdding and Editing Events Pin
Keith Plummer7-Jun-12 6:54
memberKeith Plummer7-Jun-12 6:54 
GeneralMy vote of 5 Pin
Nilesh Patil Kolhapur24-May-12 21:13
memberNilesh Patil Kolhapur24-May-12 21:13 
QuestionColor on event dates Pin
Mik Jensen13-May-12 1:37
memberMik Jensen13-May-12 1:37 
QuestionShow any month Pin
sai21808-May-12 4:30
membersai21808-May-12 4:30 
AnswerRe: Show any month Pin
sai218011-May-12 2:57
membersai218011-May-12 2:57 
GeneralGood Job Pin
sharon.s198711-Apr-12 6:51
membersharon.s198711-Apr-12 6:51 
GeneralMy vote of 5 Pin
sharon.s198711-Apr-12 6:49
membersharon.s198711-Apr-12 6:49 
GeneralMy vote of 5 Pin
manoj kumar choubey27-Mar-12 23:26
membermanoj kumar choubey27-Mar-12 23:26 
QuestionWeek numbers Pin
sigenstrøm4-Oct-11 6:25
membersigenstrøm4-Oct-11 6:25 
QuestionI can't show the last month date Pin
Member 458547913-Apr-11 19:05
memberMember 458547913-Apr-11 19:05 
GeneralMy vote of 4 Pin
subhajit Giri20-Jan-11 20:09
membersubhajit Giri20-Jan-11 20:09 
GeneralMy vote of 5 Pin
TejuKrishna25-Oct-10 22:05
memberTejuKrishna25-Oct-10 22:05 
GeneralMy vote of 5 Pin
sajidbanday2-Sep-10 20:24
membersajidbanday2-Sep-10 20:24 
GeneralMy vote of 5 Pin
vahidmir18-Jul-10 20:07
membervahidmir18-Jul-10 20:07 
Generalthanx Pin
grace871-Jun-10 23:25
membergrace871-Jun-10 23:25 
GeneralMutilanguage in EventCalendar Pin
billgate_qn9-May-10 19:20
memberbillgate_qn9-May-10 19:20 
Generaldayrender Pin
spamola16-Apr-10 10:07
memberspamola16-Apr-10 10:07 
QuestionThe Source Code does't compile Pin
theodoraaaa17-Jan-10 4:41
membertheodoraaaa17-Jan-10 4:41 
AnswerRe: The Source Code does't compile Pin
mimimimilaw19-Mar-10 22:50
membermimimimilaw19-Mar-10 22:50 
GeneralRunning the projecty locally Pin
valery1322137-Jan-10 20:18
membervalery1322137-Jan-10 20:18 
GeneralRe: Running the projecty locally Pin
Neeraj Saluja7-Jan-10 21:01
memberNeeraj Saluja7-Jan-10 21:01 
QuestionCan I have the source code of EventCalendar.dll and EventCalendar.pdb Pin
hon1234567-Jan-10 17:04
memberhon1234567-Jan-10 17:04 
AnswerRe: Can I have the source code of EventCalendar.dll and EventCalendar.pdb Pin
Neeraj Saluja7-Jan-10 20:58
memberNeeraj Saluja7-Jan-10 20:58 
GeneralRevert to current date Pin
nrlamprecht24-Nov-09 22:13
membernrlamprecht24-Nov-09 22:13 
QuestionWhy can't work well in vs2008? Pin
panpcx14-Nov-09 2:32
memberpanpcx14-Nov-09 2:32 
AnswerRe: Why can't work well in vs2008? Pin
panpcx14-Nov-09 3:31
memberpanpcx14-Nov-09 3:31 
QuestionHow to run locally Pin
Member 34028867-Oct-09 3:28
memberMember 34028867-Oct-09 3:28 
GeneralWhich one to download Pin
nainakarri5-Aug-09 5:01
membernainakarri5-Aug-09 5:01 
GeneralRe: Which one to download Pin
Neeraj Saluja5-Aug-09 9:53
memberNeeraj Saluja5-Aug-09 9:53 
GeneralRe: Which one to download Pin
nainakarri6-Aug-09 2:43
membernainakarri6-Aug-09 2:43 
GeneralRe: Which one to download Pin
Neeraj Saluja6-Aug-09 8:37
memberNeeraj Saluja6-Aug-09 8:37 
GeneralRe: Which one to download Pin
nainakarri6-Aug-09 23:50
membernainakarri6-Aug-09 23:50 
QuestionIn case of Event is of more than one day then How to get multiple selection of Row...in Same Table Cell Like OutLook-Calendar Pin
NileshUpadhyay27-May-09 4:36
memberNileshUpadhyay27-May-09 4:36 
QuestionHow to remove > Pin
Member 39395614-May-09 1:40
memberMember 39395614-May-09 1:40 
AnswerRe: How to remove > Pin
Ithilmir23-Jul-09 11:10
memberIthilmir23-Jul-09 11:10 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 19 May 2008
Article Copyright 2006 by Neeraj Saluja
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid