Click here to Skip to main content
Click here to Skip to main content

Holiday Calendar Control Webpart

, 18 Sep 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
An easy way to create a Calendar control webpart with ListView connection
1.JPG

Introduction

In this example, we are going to build a calendar control webpart that displays summarized holidays which are defined by standard ListView webpart on the same web page.

Background

For developing a webpart for SharePoint server (in our case VS2008), we need VS extension for SharePoint.

Using the Code

Step 1: Create a new project named “MyCalendar”. Select Trust Level to Full trust (Deploy to GAC).

2.JPG

Delete Default created Webpart1 folder in your solution.
Add a new web part control to your mycalender project and named it as MyCalendarControl.

3.JPG

Add System.Data and System.Drawing references to your project (under .NET Tab). After that, you will get the following kind of file structure on your solution explorer:

4.JPG

The following fields are responsible for creating a connection to a list web part:

private IWebPartTable _provider;
private ICollection _tableData;

[ConnectionConsumer("Holiday List")] attribute is necessary for Web Parts to consume data from Web Parts.

Now we are going to invoke DayRenderEventhandler so we need to add:

CusCalender.DayRender += new DayRenderEventHandler(CusCalender_DayRender); 

To populate calender days color according to the list value, we have to go through _tableData collection:

if (_tableData != null) {

foreach (DataRowView rowView in _tableData) {
string widgetCode = rowView.Row[1].ToString();
DateTime dateSold = Convert.ToDateTime(rowView.Row[2].ToString());
if (dateSold.Date == e.Day.Date.Date) {
e.Cell.BackColor = Color.Red;
e.Cell.ToolTip = widgetCode;
String url = e.SelectUrl;
e.Cell.Controls.Clear();
HyperLink link = new HyperLink();
link.Text = e.Day.Date.Day.ToString();
link.ToolTip = widgetCode;
link.NavigateUrl = url;
e.Cell.Controls.Add(link);
}
}
} 

Now our development part is over. We have to set the part for deployment. To do that, go to project property by write clicking over your project and set the MOSS site part you want to test. In my case, it is http://moss:2397/:

5.JPG

Now build the project and deploy it. After successful deployment, you can see your webpart in the webpart gallery.
Now add that web part to your page. For that, go to Site Action-> Edit Page -> Add Web Part:

6.JPG

The next step is to create a list containing Holidays and dates.
Create an Excel file and enter the holidays in a worksheet.

7.JPG

For that, go to Site action->Create->Custom List-> Import from spread sheet, name it OurHolidays and select range of sheet or you can create it manually rather than by importing the spread sheet.

8.JPG

Then, you will get the following kind of list:

9.JPG

Now go to the Home page and add that list to your page.

After adding that, you will get a page similar to the one shown below:

10.JPG

Now create a connection to List:

11.JPG

That's it.

History

  • 05-Oct-2009: Initial update 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Lalith Gallage
Software Developer (Senior) Sri Lanka Telecom
Sri Lanka Sri Lanka
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberprabhakamaji2-Dec-11 22:15 
not bad

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 | Mobile
Web04 | 2.8.141015.1 | Last Updated 18 Sep 2009
Article Copyright 2009 by Lalith Gallage
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid