IT Community - Software Programming, Web Development and Technical Support

Event Calendar [ ASP.NET 2.0 / C# ]

This is a discussion on Event Calendar [ ASP.NET 2.0 / C# ] within the ASP and ASP.NET Programming forums, part of the Web Development category; Introduction Tracking anything in dates is one of the common requirement now a days. Tracking events, project milestones, tracking history, ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-10-2007, 06:43 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Event Calendar [ ASP.NET 2.0 / C# ]

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-10-2007, 06:44 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default 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 :
[IMG]file:///C:/DOCUME%7E1/SUNDER/LOCALS%7E1/TEMP/moz-screenshot.jpg[/IMG]
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-10-2007, 06:45 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default 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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-10-2007, 06:46 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default 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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-10-2007, 06:46 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default 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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-10-2007, 06:53 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Download source

Dounload the Attached File ....
Attached Files
File Type: zip EventCalendar_demo.zip (42.3 KB, 19 views)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-10-2007, 07:13 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Default giving each event a different color

Gud job ! Sundaram..

hi,

Please how can I add different colors to calendar events per row, while I retreiving each row from database, so that I can diffrenciate between events;
Like this way, I am getting this error when I am trying to add a row to the calendar by giving it a specific color.
"CS0200: Property or indexer 'System.Data.DataRowCollection.this[int]' cannot be assigned to -- it is read only"
the error is at this line: Calendar1.EventSource.Rows[j]=dr;
Please a help!!!!

///////////////////////////////////////////////////////////////////////////////////////
int j=0;
// Yesterday's Events
j++;
dr = dt.NewRow();
dr["Id"] = idCount++;
dr["EventStartDate"] = DateTime.Now.AddDays(-1);
dr["EventEndDate"] = DateTime.Now.AddDays(-1);
dr["EventHeader"] = "My Yesterday's Single Day Event";
dr["EventDescription"] = "My Yesterday's Single Day Event Details";
dt.Rows.Add(dr);
Calendar1.BackColor=Red;
Calendar1.EventSource.Rows[j]=dr;
// Three Day's Event Starting Tomorrow
dr = dt.NewRow();
dr["Id"] = idCount++;
dr["EventStartDate"] = DateTime.Now.AddDays(1);
dr["EventEndDate"] = DateTime.Now.AddDays(+3);
dr["EventHeader"] = "My Three Days Event";
dr["EventDescription"] = "My Three Days Event Details, which starts tomorrow";
dt.Rows.Add(dr);
Calendar1.BackColor=Red;
Calendar1.EventSource.Rows[j]=dr;
//////////////////////////////////////////////////////////////////////////////////////

Regards

M.Ramesh
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-10-2007, 07:15 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Re: giving each event a different color

Added the Support for the Fore Color and back Color. You can refer to the attached Demo for the same.

Thanks,

Sundaram.M
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 09-10-2007, 07:17 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Default Re: giving each event a different color

Thanks Sundaram,

I gave the heading field a backgound & forecolor at the instance I want as random turn, also it works this way without adding the EventBackColor or EventForeColor into calendar component.



Regards,

M.Ramesh
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 09-10-2007, 07:20 AM
SaravananJ SaravananJ is offline
D-Web Programmer
 
Join Date: Aug 2007
Posts: 79
SaravananJ is on a distinguished road
Default Re: giving each event a different color

Hi

I was able to set event style by replacing the "<br />" tag in the EventCalendarDayRender event handler with a div tag like this "<div class=\"" + EventDivStyle + "\">", where EventDivStyle is a new property I added to the EventCalendar class.

Then you can set the EventDivStyle property of the control to a div css style.
__________________
J.Saravanan
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-10-2007, 08:07 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Re: giving each event a different color

Yes we can do it that way as well. The reason why Event level Back ground and Fore Color has been introduced is - I wanted to keep it very simple , keep the Event standardised and thus kept then implementation away from the Developer.

Thanks

M.Sundaram
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-10-2007, 08:08 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Re: giving each event a different color

Well Yes, you can do it that way also. Probably other similar way could be randomising the color and provide that as EventBackColor and EventForeColor for every Event.

Thanks ,

M.Sundaram
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse event varghese HTML, CSS and Javascript Coding Techniques 1 09-18-2007 08:31 AM
I get a javascript error when I click on my calendar Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 09-13-2007 06:04 AM
event.clientX and event.clientY is working in IE but not work in firefox? senraj HTML, CSS and Javascript Coding Techniques 2 08-08-2007 05:27 AM
Window event Kamalakannan HTML, CSS and Javascript Coding Techniques 1 07-30-2007 04:21 AM
event bubbling sivakumar ASP and ASP.NET Programming 1 07-17-2007 12:36 AM


All times are GMT -7. The time now is 10:52 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0