5,117,952 members and growing! (12,468 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate License: The Code Project Open License (CPOL)

Event Calendar [ ASP.NET 2.0 / C# ]

By Neeraj Saluja

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.
C# 2.0, C#.NET, .NET 2.0, ASP.NET, VS2005, VS, Dev

Posted: 29 Nov 2006
Updated: 7 May 2008
Views: 105,421
Announcements



Search    
Advanced Search
Sitemap
29 votes for this Article.
Popularity: 5.91 Rating: 4.04 out of 5
2 votes, 6.9%
1
1 vote, 3.4%
2
2 votes, 6.9%
3
10 votes, 34.5%
4
14 votes, 48.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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 varoius 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 f 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 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


.NET Professional, working with a leading global firm.

Primarily works in ASP.NET 1.1, ASP.NET 2.0, C# with Oracle and MS SQL Server 2000 as backend.

Learning .Net ...

[ My Linked In Profile ^ ][ MicrosoftTalks ^ ]

Occupation: Web Developer
Location: United States United States

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 60 (Total in Forum: 60) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGreat contributionmemberAnil Srivastava0:14 28 Mar '08  
Generalnice workmembershenji12354617:18 27 Mar '08  
GeneralGreat Articlememberjoshc1:01 27 Mar '08  
GeneralGreat ArticlememberMajid Malik0:57 27 Mar '08  
GeneralPopUp on Mouse OvermemberGovardhana Reddy4:30 28 Feb '08  
GeneralGetting Error setting the Event Calendar up...memberjohninkum2@yourehelp.com17:46 25 Feb '08  
GeneralRe: Getting Error setting the Event Calendar up...memberNeeraj Saluja21:34 25 Feb '08  
QuestionHoverMenuExtender [modified]memberNickKa5:39 17 Dec '07  
GeneralRe: HoverMenuExtendermemberNickKa13:10 17 Dec '07  
GeneralDo you have VB versionmemberdfourlive11:04 16 Oct '07  
Generaldefault.aspx.vbmemberjadams_WCG11:12 5 Mar '08  
GeneralHimemberCharlP22:16 1 Oct '07  
GeneralVery nicememberPete O'Hanlon5:08 31 Aug '07  
GeneralVery Coolmembermerlin9814:59 31 Aug '07  
Generalgood job!memberThe One And Only Ngel9:15 16 Aug '07  
GeneralHow to add mouse hover in ASP.Net 2.0 calendar controlmemberVipin Narayane19:49 29 Jul '07  
Generalhttp://slmhi.info/Calendar/tabid/620/Default.aspxmemberyi_huangyi_yi_new@hotmail.com4:53 10 Jul '07  
GeneralMaking cell updatablemembersharma sanjeev0:54 8 Jun '07  
GeneralRe: How can we generate summarymemberNeeraj_Saluja8:43 5 Jun '07  
GeneralFirst date displayed and last date displayedmemberljunquera10:12 30 May '07  
GeneralRe: First date displayed and last date displayedmemberGralov3:59 29 Nov '07  
QuestionNicemembersides_dale12:19 19 May '07  
GeneralEnable html to tooltip?membercherylng12:21 9 May '07  
GeneralRe: Enable html to tooltip?memberNeeraj_Saluja10:24 13 May '07  
Generalgiving each event a different colormemberranine22:49 16 Apr '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 May 2008
Editor:
Copyright 2006 by Neeraj Saluja
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project