Click here to Skip to main content
Licence CPOL
First Posted 29 Nov 2006
Views 451,553
Downloads 12,335
Bookmarked 233 times

Event Calendar [ ASP.NET 2.0 / C# ]

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.
2 votes, 4.0%
1
1 vote, 2.0%
2
3 votes, 6.0%
3
14 votes, 28.0%
4
30 votes, 60.0%
5
4.45/5 - 50 votes
3 removed
μ 4.18, σa 1.74 [?]

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)

About the Author

Neeraj Saluja

Web Developer

United States United States

Member
.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 ^ ][ MicrosoftTalks ^ ]


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWeek numbers Pinmembersigenstrøm6:25 4 Oct '11  
QuestionI can't show the last month date PinmemberMember 458547919:05 13 Apr '11  
GeneralMy vote of 4 Pinmembersubhajit Giri20:09 20 Jan '11  
GeneralMy vote of 5 PinmemberTejuKrishna22:05 25 Oct '10  
GeneralMy vote of 5 Pinmembersajidbanday20:24 2 Sep '10  
GeneralMy vote of 5 Pinmembervahidmir20:07 18 Jul '10  
Generalthanx Pinmembergrace8723:25 1 Jun '10  
GeneralMutilanguage in EventCalendar Pinmemberbillgate_qn19:20 9 May '10  
Generaldayrender Pinmemberspamola10:07 16 Apr '10  
QuestionThe Source Code does't compile Pinmembertheodoraaaa4:41 17 Jan '10  
AnswerRe: The Source Code does't compile Pinmembermimimimilaw22:50 19 Mar '10  
GeneralRunning the projecty locally Pinmembervalery13221320:18 7 Jan '10  
GeneralRe: Running the projecty locally PinmemberNeeraj Saluja21:01 7 Jan '10  
QuestionCan I have the source code of EventCalendar.dll and EventCalendar.pdb Pinmemberhon12345617:04 7 Jan '10  
AnswerRe: Can I have the source code of EventCalendar.dll and EventCalendar.pdb PinmemberNeeraj Saluja20:58 7 Jan '10  
GeneralRevert to current date Pinmembernrlamprecht22:13 24 Nov '09  
QuestionWhy can't work well in vs2008? Pinmemberpanpcx2:32 14 Nov '09  
AnswerRe: Why can't work well in vs2008? Pinmemberpanpcx3:31 14 Nov '09  
QuestionHow to run locally PinmemberMember 34028863:28 7 Oct '09  
GeneralWhich one to download Pinmembernainakarri5:01 5 Aug '09  
GeneralRe: Which one to download PinmemberNeeraj Saluja9:53 5 Aug '09  
GeneralRe: Which one to download Pinmembernainakarri2:43 6 Aug '09  
GeneralRe: Which one to download PinmemberNeeraj Saluja8:37 6 Aug '09  
GeneralRe: Which one to download Pinmembernainakarri23:50 6 Aug '09  
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 PinmemberNileshUpadhyay4:36 27 May '09  

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.

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