What is Web Part?
Modern web sites have different elements on their web pages. Each
one of these elements provides unique functionality to end users. Sometimes
these elements can be configurable or sometimes these events can talk to each
other. These elements occupy rectangular areas on a web page. Different
technologies use different words for these elements. Some technologies call
them portlets. Some technologies call them widgets. SharePoint chooses to call
them WebParts.
WebParts is an integral portion of ASP.NET 2.0. They were first
introduced with SharePoint 2003 before ASP.NET 2.0. ASP.NET 2.0 adopted them,
and SharePoint 2007 WebParts were largely built upon the ASP.NET 2.0 WebPart
framework. In the previous chapter, I had an overview of what a basic WebPart
is and how you would use and configure a basic WebPart. If you are unfamiliar
with WebParts, I would strongly recommend reading that section before reading
this chapter. In the previous chapter, you also wrote a simple HelloWorld
WebPart. In this chapter, you will further your knowledge and look at all
aspects of writing more involved and complicated WebParts.
What is SharePoint Pages?
SharePoint pages are simply ASPX's that you would use to browse
through your SharePoint web site. Some of these pages come from the file system
and are called application pages, whereas some other pages come from the
database and are called site pages. There are unique differences between the
usage and deployment of application pages and site pages. Also, some of these
pages can be used to host WebParts. Sometimes they are called as WebPartPages,
but WebPartPages are usually site pages. Technically speaking, you can have an
application page host WebParts as well, but as you will learn by convention
application pages seem to have a different purpose in SharePoint than site
pages.
Using SharePoint Designer with WebParts
There are three ways to deliver functionality in SharePoint.
Through the browser
Through SharePoint Designer
Through Visual Studio
Each one of these options is successively more complicated and
more compelling in its effort and results. In the previous chapter, you
customized the content editor WebPart through the browser. Subsequently, in
this chapter, you will start by looking at customizing a rather important out
of the box WebPart using SharePoint Designer.
The specific WebPart you will be working with is the XSLT List
View WebPart, referred to in code as the XsltListViewWebPart. There used to be a rather important WebPart in SharePoint 3.0
called the DataViewWebPart. The XsltListViewWebPart is a better and improved replacement for
the DataViewWebPart. The DataViewWebPart is still available, but the
XsltListViewWebPart is much easier and better to use, and I hope you will agree
with me by the end of a real-world example.
To begin, I created a simple list based on the Custom List
template. Then I added a column and called it "Population". This
column will hold numeric data, so I made it a "Number" kind of a
column. If you prefer
to be adventurous and create your very own sample data.
Once my list is populated with some sample data, I will next start
using the XsltListViewWebPart to customize the presentation of data in my List.
To recap, my source data is a Custom List with a column called
"Population". I put in some sample data to show populations of the
top 50 most populous countries in the world.
First, start SharePoint Designer 2010. SharePoint Designer 2010 is
a tool that ships with Office 2010. It is intended for use by developers and
moderately sophisticated business users. The equivalent tool in SharePoint 2007
was SharePoint Designer 2007. SharePoint Designer 2010 can be used only with
SharePoint 2010 sites; it cannot be used with SharePoint 2007 sites. Therefore,
if you have SharePoint 2007 sites to manage as well, you can install SharePoint
Designer 2007 and SharePoint Designer 2010 side by side on the same machine.
However, it is important to note that if you need to install SharePoint
Designer 2007 and SharePoint Designer 2010 on the same machine both of them
will need to be 32 bit only. You cannot have 64 bit office 2010 and SharePoint
Designer 2007 on the same machine. Personally speaking, I virtualize my work,
so this is never an issue for me anyway.
When prompted to enter a site name enter, http://SiteName. If you
have worked with SharePoint Designer 2007 before you would note that SharePoint Designer 2010
presents a completely different task oriented UI. What you should intend to do next is to edit the
site home page and use the XsltListViewWebPart to display the information from the countries
list in a user-friendly form. In SharePoint Designer 2010 with your site open in the
customization section, click the edit sites home page link
Clicking on the edit site home page link opens the home page of
the site in edit mode. Next, click the left WebPartZone and then click the Insert tab on the ribbon in
SharePoint Designer. Under the insert, look for the data view button. Click the data view button and
choose the countries list under lists This would insert the country's list using the
XsltListViewWebPart
If you saved the homepage in SharePoint Designer, refresh the page
in your browser and you should see the countries list data surface on the home page of the site.
But let's make it a little bit more interesting. Go ahead and
click any of the numeric population cells you see on the right. With your cursor in the numeric population
cell, look for the options tab under list view tools in the SharePoint Designer ribbon. Click the
conditional formatting button and then choose format column.
You will next be prompted with two dialog boxes: the first asks
you for a condition for the column and the second asks you for a visual formatting style. Using these two
dialog boxes, choose to format countries with population greater than 80,000,000 with a background color of
pink. Next, save the page and using your browser visit http://SiteName. Note that the country's list
information is showing on the homepage. Go ahead and sort the title column in ascending order. Now note that
the formatting information you specified is carried through even when the sort order is changed.
As you can see, the XsltListViewWebPart gives you immense
flexibility in formatting how your list looks in the browser. Before jumping into the next section, I'd
like you to try two other things. First, I'd like you to see some other WebParts you can insert
using SharePoint Designer on a web page and how you can customize them. Go ahead and play with
SharePoint Designer 2010 a little.
The second thing, and perhaps the more interesting, I'd like you
to try is to visit the countries list in the browser one more time, and click the list tab in the ribbon.
Look for the Modify View dropdown and choose Modify in SharePoint Designer.
No comments:
Post a Comment