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.
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:
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 )
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
- A class which extends
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
EventBackColor: ColumnName of the Column to specify the Back Color for the event.We can specify any Color Name which belongs to
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.
Support for Fore and Back Color for Events has been added. Click here to download its demo
Support for Events which spills over more that one days has been added. Click here to download its demo
Basic Event Calendar with support for Events which occurs on a single date Click here to download its demo
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.