Vision
Exploring the Data View Web Part
Written by: Margriet Bruggeman, Nikander Bruggeman.
February 19, 2009
Exploring the Data View Web Part
Companies typically use a multitude of repository types to store and manage their data. A company may use SQL Server to store relational data; the Windows file system for storing semi-structured data and eXtensible Markup Language (XML) files to hold hierarchical data. The need to aggregate and manage data in a central location is a very common requirement within portal environments. To cater to this need, you could build custom Web Parts using Visual Studio.NET to incorporate various data sources. Instead, for a range of scenarios, you will want to try to use the Data View Web Part first. The Data View Web Part is an advanced tool that allows you to create solutions for viewing and managing data in a fraction of the time it would take you to build a similar solution in Visual Studio.NET. The Data View Web Part lets you view and manage data coming from different data sources, like Web services, SharePoint lists and server-side scripts.
Data View Web Parts are able to retrieve data from various data sources in the form of XML even if the data itself in its original form is not XML, and make it very easy to adjust the appearance of that data by applying eXtensible Stylesheet Language Transformations (XSLT) to it. XSLT is used for transforming the structure of an XML document. The XML data within a Data View Web Part can be formatted using the Microsoft Office SharePoint Designer’s Design view. The next procedure explains how to open a SharePoint page in design view using a Internet Explorer.
- Open Internet Explorer and navigate to a SharePoint site.
- Click the Page button at the upper right corner. If SharePoint Designer is installed on your machine, this opens a menu that contains the option Edit with Microsoft Office SharePoint Designer. Click Edit with Microsoft Office SharePoint Designer, which by default, opens the SharePoint site in SharePoint Designer’s Design view.
- If the page is opened in another view, you can switch back to Design view by clicking the Design tab at the bottom.
The Data View Web Part offers many possibilities, such as consuming various data sources, sharing data sources, defining the look and feel of data overviews, and adding editing capabilities to data overviews. The Data View Web Part is all about aggregating and managing data from various data sources. The first thing you need to learn about the Data View Web Part is how to import and display data. To start this discussion, we will take a closer look at data sources, data source libraries, and SharePoint Designer.
Importing and displaying Data
From the perspective of the Data View Web Part, a data source is a repository of information or an end point that provides access to an information repository, for example, a database or a Web service. The Data Source Library is the main entry point for accessing and managing data sources within SharePoint sites.
SharePoint Designer, based on FrontPage technology, is a powerful tool that makes both Windows SharePoint Services (WSS) 3.0 and Microsoft Office SharePoint Server (MOSS) 2007 implementations a lot easier. SharePoint Designer lets you define new data sources, add Data View Web Parts to SharePoint Web pages that access, and display these data sources in a visual way. Manipulating the Data View Web Part visually might seem to have to do less with software development when compared to typing code yourself, but the fact of the matter is, nowadays creating software becomes more and more abstract and visual.
Using the Data Source LibraryIn our experience, most developers oversee the Data View Web Part and create a custom solution to access a data source. This often happens because a developer is more familiar with Visual Studio.NET then SharePoint Designer. It is advisable to add the Data View Web Part (and SharePoint Designer) to your bag of tricks because it can be a real time saver.
The Data View Web Part allows people who are not developers to manipulate data sources. Although we believe the Data View Web Part is easy enough to use so non-developers can use it to manipulate information, this does not seem to happen a lot at the companies we visit. Creating gateways to data sources is often considered the responsibility of developers, which excludes other types of users from using the Data View Web Part.
To use a Data View Web Part to display data, a reference to that data source must be referenced in the Data Source Library task pane. The Data Source Library offers access to data that is stored within SharePoint Web sites, as well as external data sources. As long as you have access rights to a data source, you can manage it via the Data Source Library task pane. In the Data Source Library task pane under the Current Site section, you will see lists and libraries that the site contains, plus any other data sources you have attached. The data sources are grouped under section headers where the data sources are accessed using the same method, with the number of currently added data sources in brackets.

SharePoint Designer automatically creates data sources for the default lists and libraries that exist within a given SharePoint site. Out of the box, entries for the following lists are created in the Data Source Library and added in the SharePoint Lists section: Announcements, Calendar, Links, Tasks, and Team Discussion. There is also an entry for the Shared Documents document library, which is listed under the SharePoint Libraries section.
Creating a new SharePoint list or library using Data Source LibrarySharePoint lists and libraries are used within SharePoint implementations to not only store information directly targeted at the end user, for instance, documents, tasks, and events. Lists and libraries can also be used to store configuration information or information required to provide a feature. You can also create lists to store your own configuration information and reuse this information as metadata for documents that you add to a document library. As we have already seen, SharePoint Designer automatically adds references to lists and libraries in your current site, so you do not have to add manually references to these lists and libraries yourself. Once you have a reference to a list or library as a data source, the Data View Web Part lets you display the SharePoint list or library in a different way. You can also link the list or library to another data source, thereby allowing you to merge or join data from several data sources; more about this later in this article.
However, what the Data Source Library task pane, does allow you to do, is to create new lists and libraries. Follow the next procedure to create a SharePoint list as a data source.
- Open the Data Source Library task pane, click the Data View menu and then click Manage Data Sources.
- Click the + sign to the right of SharePoint Lists.
- Click Create new SharePoint list.
- On the SharePoint Content tab in the New dialog box, click Lists. SharePoint Designer contacts the current SharePoint Web site and asks for a list of lists templates that you can use as a basis for your new list. SharePoint Designer then displays these list templates in the New dialog box.
- Click one of the list templates, enter a name for your new list in the Specify the name for the new list text box and click OK. SharePoint Designer uses the name you enter for the URL and the Title of the list.
Creating a SharePoint library as a data source is almost the same as creating a SharePoint list. Follow the next procedure to create a SharePoint library from the Data Source Library task pane.
- An alternative way of opening the Data Source Library task pane is to click the Task Pane menu and click Data Source Library.
- Expand the SharePoint Libraries section by clicking the + sign.
- Click Create new SharePoint libraries.
- On the SharePoint Content tab in the New dialog box, select Document Libraries. Again, SharePoint Designer asks the current SharePoint Web sites for a list of library templates, which will then be displayed in the New dialog box. Although the link caption says Document Libraries, all kinds of libraries templates site are listed. For instance, the Document Library section can also contain the form or wiki page library templates.
- Select the library you want to create. Enter a name for the new list data source in the Specify the name for the new document library text box, again remember that this is the URL and the Title for the Library, and then click OK.
You have now created a new list and library using the Data Source Library task pane, and SharePoint Designer automatically added references to those lists and libraries in the Data Source Library task pane. Next, we will add references to other data sources so that they appear in the Data Source Library task pane.
Adding a Database as a data sourceIt is good practice to store relational data in databases. Most companies that use SharePoint technologies to build portals sometimes need to reuse this data within the portal. For example, we recently had to expose customer information stored in a relational database on a portal Web page. We had to resist our first instinct to grab Visual Studio.NET and create a new SharePoint Web Part, and ended up saving a couple of hours of our time by using the Data View Web Part instead. If you find yourself in a situation where you need to reuse data stored in a relational database, you should start by adding the database as a data source by specifying a database connection for it. After that, you are free to use the data from the database within the Data View Web Part. The next procedure shows you how to add a database as a data source.
- Open the Data Source Library task pane using one of the methods we described in the following section.
- Expand the Database Connections section, and click Connect to a database, which opens the Data Source Properties dialog box.
- Select the General tab and enter a descriptive name for the database connection, so you will know when you see the name what database it refers to.
- Select the Source tab and click Configure Database Connection button. The Configure Database Connection dialog box is displayed.
- Type the name of the database server in the Server Name text box.
- Choose the type of authentication you want to use, by selecting one of the following options:
- Save this username and password in the data connection. Here you can specify a username and password that will be saved in the data connection. Selecting this option will save the specified username and password as clear text in the data connection, which poses a security risk. A dialog box is displayed warning you of this. If the database server is using Microsoft SQL server, then to use this option, the SQL Server is configured for mixed authentication, that is both Windows authentication and SQL authentication. The user name you specify is an SQL username and not an Active Directory (AD) user name. If you are using this option, you should persuade your IT department to implement some secure method of transferring data between your SharePoint servers and the SQL database, such as IP Sec or VPN.
- Use Single Sign-On authentication. This option is only available when the SharePoint site is using a Shared Services Provider (SSP), which is part of MOSS 2007, and your Shared Services Administrator has enabled and configured single sign-on. When you click the Settings button the Single Sign-On Settings dialog box opens, where you can specify the Application Name, the Application field to use as the username and the Application field to use as the password in the appropriate text boxes.
- Use custom connection string. Here you can specify an OLEDB connection string to connect to the database. Click the Edit button to open the Edit Connection String dialog box where you can specify the provider name and the connection string. You will probably need the help of your database administrator for this option.
- Windows Authentication. You will see this option if your organization has installed only WSS 3.0 on a single server, and SQL Server is installed on the same server as WSS 3.0.

- Click Next when you have configured the authentication method. The Configure Database Connection dialog box is displayed.
- Select a database from the Database dropdown list.
- If you want to use a table or view, select the Select a table or view radio button and select the table or view from the list box. It is also possible to create your own query by checking the or select custom Select, Update, Insert, and Delete commands using SQL or stored procedures radio button.
- Click Finish. This brings you back the Data Source Properties dialog box.
- Click OK to finish the creation of a database connection data source.
Now that you have added a database as a data source, you are ready to use it within the Data View Web Part. We like this option and use it a lot, although maybe not as often as we use a SharePoint list or library as a data source within the Data Source Library task pane.
Adding an XML file as a data sourceXML files are commonly used in organizations because they are very suitable for storing hierarchical data. We remember a company that hired us to build a Web-based form generator. The company used a relational database model to describe medium-sized (around 100 fields) form definitions. If a visitor came to their Web site and submitted one of those forms, the data was added, again, to a relational database model. It would often take literally hundreds if not thousands of separate SQL queries to build a form based on a definition and add the user data to the database.
We were able to improve the speed of constructing forms and adding data to a repository enormously by switching to an XML repository. Not only did the performance of the Web-based form generator increase several times, reducing the number of required SQL queries to a maximum of two, the upper limit of supported fields in a form increased from around a hundred fields to tens of thousands of fields. Once you reach Web-based forms of that size, limits do not count anymore, since you will not be able to find a user who is prepared to take a week of his or her life to fill-in and submit such a form. By the way, we were not the only ones who has come up with the idea to store form definitions and form data in XML; Microsoft’s InfoPath is an excellent example of a tool that does just that.
When SharePoint Designer first opens the Data Source Library task pane it will search your current site for any XML files and will list them under the XML Files section. To add other XML data sources to your SharePoint site follow the next procedure.
- Open the Data Source Library task pane as described previously, if it is not already open.
- Expand the XML Files section and click Add an XML file. This opens the Data Source Properties dialog box.
- Click Browse, to open the File Open dialog box, and select the XML file you want use as a data source. Next, a warning popup window appears asking if you would like to import the specified XML file in order for it to be used as a data source. Click OK.
- In the Import dialog box click OK. Now you have uploaded an XML file to the root of your SharePoint site and a data source is added to the XML Files section.
You can move the XML file to one of your document libraries, and SharePoint Designer will amend the data source accordingly. By moving the XML file into a document libraries, means that you can edit the XML file using the browser, whereas by leaving the XML file in the root of the SharePoint site, then only users who have access to SharePoint Designer can modify it.
XML files are great for solving specific types of problems, as you have seen earlier in this section. It is not hard to add an XML file as a data source, in fact, it is not much different than the types of data sources you have seen earlier in this article.
Server-side scriptUsing the Data Source Library you can connect to server-side scripts that are written in different programming languages like ASP.NET, and PHP. Server-side scripts have been used for years and play an essential role when it comes to generating dynamic Web sites. There is only one important condition when it comes to consuming server-side scripts: the response of a server-side script needs to be valid XML. If you want, you can use the Internet Explorer Developer Toolbar to determine if a page is valid eXtensible Hypertext Markup Language (XHTML). Any page that is XHTML compliant is valid XML and thus can be used as a data source. You can download the Developer Toolbar add-in from Microsoft’s download Web site: http://www.microsoft.com/downloads/details.aspx?familyid=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en .
Really Simple Syndication (RSS) feeds form a very important and popular source of delivering information that fall under the server-side script umbrella. If you have a Web site that does not provide RSS feeds, it will definitely cost you many visitors. On our Web sites, RSS feeds are responsible for about 70% of the traffic. If the extension of an RSS feed ends with .XML, it can be added as a data source in SharePoint Designer, via either the server-side script category or XML file category. Any RSS feed that ends with another extension, for instance, .aspx, you can only add as a data source using the server-side script category. The next procedure shows you how to add a server-side script or RSS feed as a data source.
- Open the Data Source Library task pane as described previously, if it is not already open.
- Expand the Server-side Scripts section and click Connect to a script or RSS feed. This opens the Data Source Properties dialog box.
- Click the General tab and specify a name for the data source.
- Click the Source tab and select which HTTP method you want to use. You can choose between HTTP Get and HTTP Post. The drawback of the HTTP Get method is that all parameters are shown in the URL itself. In general, if you are working with a set of parameters of a medium size or larger, choose to use the HTTP Post method.
- Select which data command you want to configure. You can choose between Select, Insert, Update or Delete.
- In the Enter the URL to a server-side script text box, enter the URL of the server-side script or RSS feed you want to connect to.
- In the case where you are using a server-side script, which requires parameters, click the Add button to add a parameter. This opens the Parameter dialog box where you can enter a name and default value. Click OK in the Parameter dialog box.
- Click OK in the Data Source Properties dialog box to add the server-side script or RSS feed as a data source.

At first sight, you might not look at a server-side script as a potential data source. Nowadays server-side scripts return responses that are better structured than they used to be. Server-side script responses that are well structured are suitable to be consumed as a data source by the Data View Web Part.
XML Web serviceIn the current development landscape, using Web services is, without a doubt, the most popular technique for implementing Service Oriented Architectures (SOA). Web services make it easy to issue Remote Procedure Calls (RPCs) over the Internet or a network using standards such as HTTP and XML. The messages exchanged between a client and a Web service, are encoded in the Simple Object Access Protocol (SOAP), a special XML dialect. The interface of a Web service is described in a language called the Web Service Description Language (WSDL), which, states the names of each Web service method and the parameters it accepts and returns.
Because Web services have to adhere to the SOAP and WSDL standards, Web services are very interoperable. SharePoint Designer can consume any Web service built on any platform using any programming language, as long as the Web service complies with the SOAP and WSDL standards.
Because of the enormous popularity, it is good news that you can add a Web service as a data source. If you want to do this, you have to know the URL for the WSDL description of the Web service. This URL ends with either ?WSDL or .wsdl. WSS 3.0 provides an extensive Web services layer that allows you to interact with different aspects of WSS and is the primary means of remote communication with SharePoint. For instance, you can use the SharePoint Web service layer to interact with servers, lists, and sites. SharePoint Server 2007 provided additional Web Services so that you can remotely access information stored in components, such as, user profile and business data catalog. For a full list of the SharePoint Web Services, refer to the WSS 3.0 and SharePoint Server 2007 Software Development Kits (SDKs). In this section, we will use one of those Web services for demonstration purposes.
There are other ways to communicate with SharePoint remotely as well. You can use Web-based Distributed Authoring and Versioning (WebDAV) to manipulate documents on a SharePoint server. Then, there is FrontPage RPC, a protocol that is powerful when it comes to working with documents on a SharePoint server. Finally, there is SharePoint RPC, a protocol that contains a plethora of functions that fall outside the scope of this article. By the way, do not be overjoyed if you start a new project that uses either one of the WebDAV, SharePoint RPC, or FrontPage RPC protocols. Programming in .NET using these protocols is not that well documented and can be quite laborious.
In this example, we are going to demonstrate how to add a web service as a data source. We are going to use the SharePoint Lists Web service, which provides methods for interacting with SharePoint lists and list data. Let’s look at how to query the Lists Web service for all the titles of the lists in a SharePoint site.
- Open the Data Source Library task pane as described previously, if it is not already open.
- Expand the XML Web Services section and click Connect to a web service. This opens the Data Source Properties dialog box.
- Click the General tab and enter a meaningful and descriptive name for the data source.
- Click the Source tab and enter the URL for the Web service in the Service description location text box. Append to the URL name _vti_bin/Lists.asmx?WSDL. Your URL should look something like: http://[Servername]/_vti_bin/Lists.asmx?WSDL.
- Click the Connect Now button to establish a connection with the web service.
- After the connection is created, the Connect Now button will change into a Disconnect button.
- Select the Select command in the Select which data command to configure list. The other commands are Insert, Update and Delete.
- In the Port list select the application protocol you want to use to access the Web service. For .NET Web Services there are two protocols available: one with a SOAP 1.1 binding called [WebServiceName]Soap, and another with a SOAP 1.2 binding called [WebServiceName]Soap12. Those options are only shown if the Web service indicates that it is able to support the multiple versions of the SOAP protocol. If the option is available to choose between multiple versions, we advice you to choose the latest version.
- In the Operations drop down list, you will find all the methods of the specified Web service. In this example, we select the GetListCollection method, which retrieves the names and Globally Unique Identifiers (GUIDs) for all the lists in the site. The Parameters list box can be used to display the names of any parameters that the Web service requires or accepts. After you select the Web service method, SharePoint Designer will fill the Parameters list box with the required parameters and their data values. If there are input parameters in the list you will have to supply these to the Web service. This can be done by hard coding the value of the parameter or by setting a parameter at run time.
- The Lists Web service does not require any parameters, so you can just click OK. The next figure shows a Data View Web Part that uses the Lists web service as a data source. Later in this article, we will show you how to create Data View Web Parts.

A considerable number of software systems today are built with SOA in mind. Many of those systems will use Web services as the primary way to connect to other systems, and let other systems connect to it. Because of this, the ability to use a Web service as a data source within a Data View Web Part is an important one. More information about SOA can be found in the green book "Application Architecture for .NET: Desiging Applications and Services". This freely downloadable book can be found at the following location: http://www.microsoft.com/downloads/details.aspx?FamilyId=A08E4A09-7AE3-4942-B466-CC778A3BAB34&displaylang=en .
Business Data CatalogThe Business Data Catalog (BDC) is one of the new features of MOSS 2007. The BDC enables you to display information coming from various types of backend applications. The BDC can act as another type of data source for the Data View Web Part. Configuring a BDC requires some work, which falls outside the scope of this article.
Creating a Linked sourceOrganizations often store data in different types of repositories, for example, XML Files and relational databases. With the Linked Source section of the Data Source Library task pane, it is possible to relate different types of data sources to each other. In this way, you can combine several types of data sources into a single data source and then use the Data View Web Part to display that data. We discuss creating linked sources later in this article.
Connecting to another libraryYou are not limited to using the Data Source Library of the current SharePoint site; you can also use the data sources as defined in the Data Source Libraries from other SharePoint sites. This makes it easier to share data sources between sites without recreating data sources and we expect you will be using this feature all the time. In fact, we like creating SharePoint sites whose single purpose in life it is to act as a central repository for hosting data sources. Of course, this only makes sense if you are planning to use a data source in multiple other sites. Creating a central SharePoint site that acts as a data source host makes it easier to find and manage data sources.
When you connect to another Data Source Library, SharePoint makes all its data sources available in the current SharePoint site. This does not mean that you are moving or copying of data sources to your site, you are simply referencing an external Data Source Library. Any deletions or modifications in the external Data Source Library will also affect the current SharePoint site. The following procedure shows you how to connect to a Data Source Library in another SharePoint site.
- Open the Data Source Library task pane.
- Click the Connect to another library link at the bottom of the Data Source Library task pane. This opens the Manage Library dialog box.
- Click the Add button in the Manage Library dialog box; this opens the Collection Properties dialog box.
- In the Display Name text box enter some text that will help you to recognize the new data source within your Data Source Library.
- Click Browse to browse for the SharePoint site that contains the Data Source Library you want to use. This opens the Choose a Web Site dialog box.
- Select a web site or type the URL of the SharePoint site and click Open.
- In the Collection Properties dialog box, click OK.
- In the Manage Library dialog box, click OK. The figure below shows the Data Source Library task pane with the data sources of the Current Site and the data sources of another SharePoint site which we used a display name of Another SharePoint Site that contains the external Data Source Library.

Now you have now created a number of datasources, and you know how to define data sources in a central SharePoint Web site location, from where you can share these data sources with other SharePoint sites. However, before going on to use them we need to take some time out to find where all these data sources are physically stored, which is the subject of the next section.
Data Source document libraryWhen you create a data source, SharePoint Designer creates a XML file that describes that data source and then stores the XML file in a document library, named fpdatasources. This is a special document library that you can only see when you use SharePoint Designer and the Folder List task pane. To view the fpdatasources document library complete the following steps:
- Open the Folder List task pane: Task Panes > Folder List.
- Expand _catalogs and fpdatasources. You should now see a list of XML files, which you can open and review the XML if you wish. You could change the XML in these files, but the next time you use the Data Source Library to amend your data sources, you will lose any amendment you enter manually, so we recommend you don’t do this.

All data sources you create are therefore stored in the SharePoint SQL content database and are therefore available not just to you, but to anyone who has the rights to use SharePoint Designer on your SharePoint Web site. Now we are ready to describe how to expose the data that these data sources contain, that is, in the next section we’re going to start to use the Data View Web Part.
Creating a Data View
Until now, you have learned how to add data source that points to various repositories so that the data in those repositories can be viewed or managed using the Data View Web Part. It is about time that you learn how to use the Data View Web Part, don’t you agree? It is only then that you will see the power of making data available as a data source. In this section, you will learn how to create a Data View that displays data coming from a data source.
The first thing you need to do when you start to create a Data View is to make sure you have added the data source to the Data Source Library. Adding data sources to a Data Source Library, we discussed in previous section. After ensuring the data source you need is present, you are ready to create a Data View. There are two ways to create a Data View we’ll discuss both of these methods in this section. The next procedure shows the first way to insert a Data view. This method uses the Folder List task pane to add a Data View.
- Open SharePoint Designer and open the SharePoint page where you want to place the Data View Web Part.
- In the Folder List task pane, on the left side of SharePoint Designer, locate your data source. This can be a list, a library, an XML file or one of the XML files in the fpdatasources document library. Select the data source and drag it onto the SharePoint page.
- Two things will happen: a Data View Web Part containing the selected data source will appear onto the SharePoint page and the Data Source Details task pane opens. The Data Source Details task pane is responsible for displaying all the elements of the selected data source. You can also open the Data Source Details task pane by going to the Data Source Library and clicking the data source and selecting Show Data from the dropdown list.
The second method for creating a Data View uses the Data Source Details task pane, which we’ll explain in the next procedure.
- Open SharePoint Designer and open the SharePoint page where you want to place the Data View Web Part.
- On the Data View menu select Insert Data View. This will place a Data View Web Part onto your SharePoint page. Next, we are going to insert the data.
- In the Data Source Library task pane, select the data source you want to add, click the data source and select Show Data. This opens the Data Source Details task pane.
- In the Data Source Details task pane, select the fields you want to add. Like other Microsoft products, you hold down the SHIFT or CTRL keys to select multiple fields at the same time.
- Click the Insert selected fields as dropdown list and select Multiple Item View.
If you just want to create a basic Data View Web Part then you are ready. If you want to customize your Data View Web Part there are plenty of options you can choose. In this section, we will discuss these options some more.
If you click the chevron icon to the top right of the Data View Web Part, you open the Common Data View Tasks action panel, where you will notice the following options.
- Filter
- Sort and Group
- Paging
- Edit Columns
- Change Layout
- Data View Preview
- Show with sample data
- Conditional Formatting
- Web Part Connections
- Parameters
- Refresh Data View
- Data View Properties

Probably the biggest advantage SharePoint has over its IBM and Oracle portal product competitors is its compelling user interface. The Data View Web Part offers advanced capabilities to create a user interface that looks good, and we think your customer expects you to use it.
Filtering DataIn most scenarios, it will not do to show all the data coming from a data source. You will typically want to filter this data. In SharePoint Designer, you can add a filter to the Data View Web Part. A filter allows you to specify a subset of all the data that your data source contains and in this way you also limit the data that are shown in the Data View Web Part. Like the List View Web Part, it is possible to add a filter toolbar to the Data View Web Part so that users themselves can filter the data and determine which subset of the data available via the Data View Web Part they can display.
Sorting and Grouping DataSharePoint Designer makes it easy to sort and group data in a Data View Web Part. Sorting data in a Data View Web Part modifies the order in which you show the data. For instance, you can sort the data alphabetically to make it look more organized. You can create complex sort expressions using the XPath Expression Builder. You can find more information about the XPath Expression Builder later in this article.
When you group data in a Data View, data within the Data View is grouped by the criteria that you specify. Sorting and grouping are related, and you cannot group data unless you have specified a sort order. Each group in a Data View can be expanded or collapsed by using the group header.
The Data View Web Part displays the data sort or group order that you have specified. You can also add a toolbar to the Data View Web Part so that users can sort or group data themselves.
PagingIn a Data View Web Part, you can limit the number of records shown per page this is called paging. SharePoint Designer will add paging navigation to the Data View Web Part for moving backward and forward through all the data. This is one of the most asked features when it comes to displaying data, so we can promise you, you will use the Paging option a lot.

If a customer is happy to use the columns that are shown by default in a Data View Web Part, he or she is probably very easy to deal with. We doubt you are that lucky, so you will be glad to learn that you can influence which fields are displayed by the Data View Web Part. You can add, move or remove the columns or rows that are shown using the option Edit Columns. This option is only present when you are working with a Data View Web Part that displays the data in an HTML table.
Changing LayoutThe data of a Data View Web Part is by default displayed in a basic table layout. This layout can be changed quickly and easily by making use of the built-in Data View layouts, of which there are 13 available, each with a preview of the layout and a description of the style. Changing the style of a Data View Web Part will remove any custom formatting that you have done previously, so we recommend you do this first before applying any custom formatting.
Data View PreviewThe Data View Preview option allows you to preview the data and offers you the possibility to show a limited the amount of data in the preview. The following options are available:
- Default. Matches the view that is shown at runtime.
- Hide all filters. Shows all available data.
- Limit to 1 item. Shows a single item.
- Limit to 5 items. Shows up to 5 items.
- Limit to 10 items. Shows up to 10 items.
- ‘No Matching Items’ Template. Shows what happens if no matching items are found and allows you to specify text for this situation.
Under the Data View Preview option there is a checkbox Show with sample data, which if selected, the Data View Web Part will fill with sample data instead of real data. This option proves to be very useful when a data source contains much data or when it takes a lot of time to retrieve data from a data source. The Show with sample data option is also convenient when the data source itself does not contain any data yet.
Conditional FormattingWith the Conditional Formatting option, it is easy to create a Data View Web Part that applies a style to a selected HTML tag or data value when the data meets specified criteria. It is possible to set conditions that change the visibility of an HTML tag or data value.
Web Part ConnectionsWith the Web Part Connections option, you can create a connection between two Data View Web Parts and in this way, when you perform an action in one Data View Web Part, it will change the contents of another Data View Web Part. The only way to create a connection between two web parts on different pages in the same SharePoint site (cross-page connection) is using SharePoint Designer.
ParametersYou can specify parameters coming from different sources such as cookies, form values and query string variables. Any parameter you specify can be used when creating Web Part connections. The discussion of this falls outside the scope of this article.
Refresh Data ViewWith the Refresh Data View option, you can refresh the content shown in the preview. After a refresh, the latest data from a data source is shown.
Data View PropertiesWhen you choose the Data View Properties option, the Data View Properties dialog box opens. Many of the other options described above open this dialog box, from which you to specify the look and feel, Paging and other options.

Creating a Read/Write Data View
You can add Data Views to a SharePoint page as either a view or a form. Forms allow you to edit the data at run time and the changes are written back to the data source. Views are great for providing overviews of data, but you can also add links to a view so that users can edit the data when they display the data in a Web page, also known as "at run time". The first thing you will learn in this section is how to create a view that displays single or multiple records. After that, you will see how to collect data from users using item forms. If you are unclear about all the differences between data views and data forms, we have provided a table as an overview of the differences between Data Views that are added to SharePoint pages as views and Data Forms where you can manage the data.
| Actions | View | Form |
| View style | Data is displayed in view mode and by clicking the Edit link it will be displayed in Edit mode. | Data will always be displayed in Edit mode. |
| Insert | X | X |
| Edit | X | X |
| Delete | X | |
| Data Sources | ||
| Lists and libraries | X | X |
| Database connections | X | X |
| XML files | X | Only local XML files |
| Server-side scripts | X | |
| XML Web Service | X | |
| Business Data Catalog | X | |
| Linked source | X |
Views are similar to the ASP.NET GridViews component. They are great for providing dense overviews of multiple rows of information. Forms are similar to the ADO.NET FormViews component. They show one or more rows of data, records, at a time, are always shown in edit mode, and are very customizable thus providing optimal flexibility.
Creating Item ViewsSharePoint Designer provides two options for inserting a data view as a view.
- Single Item View. This view displays a single record as a view. Optionally, you can provide navigation links that allow you to view the next or previous record.
- Multiple Item View. This view displays multiple records as a view.
It is possible to create read-only views or you can add editing links that allow you to edit, insert or delete records from the data view. Multiple Item Views are less suitable for implementing advanced editing scenarios. Displaying and editing multiple items at a time tends to confuse users. In general, this is solved using master-detail views, which you can achieve by connecting two Data View Web Parts, as discussed briefly previously in this article.
Adding a data view as a form is described in the next section. You can also add editing links to a form by replacing the existing form buttons. This effectively transforms a form to a view.
In the next example, we are going to use the SharePoint Announcements list as a data source for our Data View Web Part. We will also add editing links to the Data View Web Part. The next procedure shows you how to add a Data View, as a multiple item view with editing links, to a SharePoint page.
- In SharePoint Designer, go to a page and place the cursor on the page where you want to place your Data View. In this example, we will use the default.aspx page of a test SharePoint site.
- Click Data View on the menu bar and select Insert Data View. This adds an empty Data View Web Part on the page and opens the Data Source Library task pane, if it is not already open.
- In the Data Source Library task pane, expand the SharePoint Lists section.
- Click the Announcements data source and select Show Data. This opens the Data Source Details task pane.
- Hold the CTRL key down and select the Title and Expires fields. From the Insert Selected Fields as drop-down list, click Multiple Item View. Note that the order you click the fields is the order the fields will appear in the page.
- The Data View Web Part is added to the page and the Common Data View Tasks action panel opens.
- Click Data View Properties to open the Data View Properties dialog box.
- Select the Editing tab and select the following checkboxes.
- Show edit item links
- Show delete item links
- Show insert item link
- Click OK.
- Save the SharePoint page in SharePoint Designer. If this is the first time you have saved default.aspx, a Warning message is displayed, stating that saving your changes will result in customizing the page. Click Yes.
- Open it in a browser. The figure below shows a Data View Web Part with editing links, after clicking the edit link of the first record.


You can not only use the Data View Web Part to create data overviews, as its name implies, you can also add create, update, and delete functionality.
Creating Item FormsUsing the Item forms option of a Data View, are ideal for collecting data from users. Using SharePoint Designer, you can insert a Data View as a form so that users can make and save changes to the data source. Not all data sources can use a Item Form to insert data, the following types of data sources are supported.
- Lists and libraries.
- Database connections.
- Local XML files.
When inserting a data view as an Item Form you can choose between three different types of forms.
- Single Item Form. This form displays a single record as a form, each field will have its own row and the field name will be the heading for that row. This way it is easy to edit the data for on that record. SharePoint Designer provides navigational links, which you can use to move on to the next or previous record.
- Multiple Item Form. This form displays multiple records as a form. Here you can edit the data for multiple records and save all changes at the same time.
- New Item Form. This form displays blank fields for a single new record. This way you can add one new record to the data source.
In the next example, we are going to use the SharePoint Announcements list as a data source for our Data View Web Part. We will add the fields as a single item form to the Data View Web Part. Follow the next procedure to add a data view as a single item form to a SharePoint page.
- In SharePoint Designer, go to a page where you want to place your Data View. In this example, we will use the default.aspx page of a test SharePoint site.
- Click Data View on the menu bar and select Insert Data View. The Data Source Library task pane opens, if it is not already open.
- In the Data Source Library task pane, expand the SharePoint Lists section. Here you will find the Announcements data source.
- Click Announcements and select Show Data. This opens the Data Source Details task pane.
- Hold down the CTRL key, and select the Title, Created and Expires fields and then from the Insert Selected Fields as drop-down list select, Single Item Form.
- Save the SharePoint page in SharePoint Designer and then open the SharePoint page in a browser. Click the record arrow to navigate to the data you wish to amend and then click Save. The figure below shows a Data View Web Part inserted as a single item form with record 2 displayed.

Forms allow fine-grained control over the look and feel of each field. You can add create, read, update, and delete functionality for multiple items at a time. To enhance the user interaction experience, it is often preferable to create a form that can manipulate a single item at a time. Providing such functionality, is well within the reach of the Data View Web Part.

Working with Related/Linked Data Sources
Organizations often store data in different types of repositories, for instance, XML Files and relational databases. With the Linked Source data source, it is possible to relate different types of data sources to each other. This way, you can combine several types of data sources into a single data source that can be used by the Data View Web Part. In this section, you will learn how to create new types of data sources that combine the information stored in other data sources. Such data sources are also known as linked data sources, during the course of this article you will find out that working with a linked data sources is identical to working with any other data source.
Merging data sourcesBy creating a linked data source, you can merge together data from separate data sources. Such data sources need to be of the same type and they need to have a field in common that you can use to merge the information together. The WSS SDK mentions that the set of fields in both data sources have to match exactly, but this is not entirely true, as you will see later in this section.
You can only merge data sources if they are of the same type. For instance, you can merge two XML file data sources, but you cannot merge an XML file data source with a SharePoint list data source. However, you can join data sources of different types together. We discuss joining data sources in the next section.
Merging data sources allows you to create a single data source that consists of several other data sources. This single data source is a union of the other data sources.
The next example was created with one of our customers in mind, a telecom company. They knew we were working on this book and during our consulting work; they repeatedly tried to come up with cool ideas to write about. So, guys, thanks for working together, the next example is for you. In this example, we are going to create a linked data source that consists of two data sources that we will merge. The first data source is a SharePoint list called Clients. An imaginary phone company maintains this list, which contains two columns: ClientName and Minutes. The ClientName column contains the name of the customer, the Minutes column relates to the number of mobile minutes bought by the customer. The second data source is also a SharePoint list (remember, when merging data sources they have to be of the same type) called Customer. The Customer list has two columns, CustomerName and MobileMinutes. The customerName column contains the name of the customer and is really the same as the ClientName column of the first list.
Now our customer wanted a page that displayed a list of both it’s clients and customer. Follow the next procedure to link these two data sources together in one data source and show them in a Data View Web Part.
- Open SharePoint Designer and open the SharePoint page where you want to place the Data View Web Part.
- On the Data View menu select Insert Data View.
- Go to the Data Source Library task pane and expand the Linked Sources section and click Create a new Linked Source. This opens the Data Source Properties dialog box.
- Click the General tab and enter a name for the data source, for example, Customer Data.
- Click the Source tab and click Configure Linked Source. This opens the Link Data Sources Wizard window.
- On the left, under Available Data Sources, all available data sources are listed. Expand SharePoint Lists, select Customer and click Add. Select Clients and click Add. If the Data Source Library does not display a list that was made recently, you may have to click the Refresh Library link in the Data Source Library task pane.
- Click Next. The second page of the Link Data Sources Wizard is displayed.
- Select the radio button, Merge the contents of the data sources, which is the default and click Finish.
- Click OK to close the Data Source Properties dialog box.
- In the Data Source Library task pane, you will see a new data source under the section Linked Sources.

The figure below shows a visual impression of merging data in multiple data sources. As you can see, the linked data source contains the union of multiple other data sources.

It is possible to create a joined data source that consists of multiple separate data sources, which do not have to be of the same type. The data sources that you join must have at least one field in common. Since we absolutely love to watch movies, we will show how to join data sources using some data about movies we have just created. In the example discussed in this section, we created an XML file called Genres.xml, which contains movie genres and looks as follows.
<?xml version="1.0" encoding="utf-8" ? ><Genres>
<Genre>
<Id>1</Id>
<Name>Romance</Name>
<Description> Romantic feel good movies.</Description>
</Genre>
<Genre>
<Id>2</Id>
<Name>Horror</Name>
<Description>Scary stuff.</Description>
</Genre>
<Genre>
<Id>3</Id>
<Name>Science Fiction</Name>
<Description> Futuristic adventures in space. </Description>
</Genre>
</Genres>
We called the second XML file, Movies.xml, which contains a list of movies and a genre id that matches the id of the genres listed in Genres.xml. Movies.xml looks like this.
<?xml version="1.0" encoding="utf-8" ?><Movies>
<Movie>
<Name>Fallen</Name>
<GenreId>2</GenreId>
<LeadingActors> Denzel Washington, John Goodman </LeadingActors>
</Movie>
<Movie>
<Name>Music and Lyrics</Name>
<GenreId>1</GenreId>
<LeadingActors> Hugh Grant, Drew Barrymore </LeadingActors>
</Movie>
<Movie>
<Name>Intolerable Cruelty</Name>
<GenreId>1</GenreId>
<LeadingActors> George Clooney, Catherine Zeta-Jones </LeadingActors>
</Movie>
</Movies>
Create the two XML files with the content detailed above and store them in a document library, or use the procedure explained earlier in this article, “Adding an XML File as a data source”. We will use the
In the next procedure, we show you how to add the linked data source to a SharePoint page and how to make a subview within a data view.
- In the Data Source Library task pane, click the data source you just created, Movie Data, and then click Show Data.
- First, we are going to create a Data View of the Genres data source. In the Data Source Details task pane, under Genre, hold down the CTRL key, click Name and Description and then click Multiple Item View from the Insert Selected Fields as menu to insert the selected data into the Data View.
- The next thing we are going to do is to create a new column to show our subset of data. Right-click in the cell with the name Description, select Insert and then select Columns to the Right.
- Place your cursor in a cell of the new column. Do not place the cursor in the heading cell, that is do not place the cursor in the same row as the word Description.
- Then in the Data Source Details task pane, hold down the CTRL key and select Name and LeadingActors fields from the Movie folder. Click Insert selected fields as > Joined Subview. This opens the Join Subview dialog box. In this example, we are creating a subview of the movies.xml data source that is joined to the Genres.xml data source by the field genre id, which both data sources have in common. This is called a joined subview.
- In the Join Subview dialog box, select the genre id fields of both data sources. In the Genres.xml file select the field called Id, and in the Movies.xml file select GenreId.
- Click OK. The figure below shows the Data View Web Part showing the end result.

Using XPath queries within the Data View
One of the new features of SharePoint Designer 2007 is called the XPath Expression Builder, which makes is easy to use the XML Path Language (XPath) . XPath is a querying language for XML and is designed to be used in combination with the Extensible Stylesheet Language Transformations (XSLT) . XSLT is designed to transform XML documents into other documents.
You can use the XPath Expression Builder in SharePoint Designer to create a formula column. A formula column displays the results of a calculation that was performed on other data in a data source. The XPath Expression Builder can be used to help build expressions, or calculations that other options of the Data View Web Part can use, for example using our previous example, you may wish to conditionally format the data in the Minutes column if the number of minutes a customer uses goes above 10,000. This is a very simple example, and you could use the default Condition Criteria dialog box to create this, however under the covers this dialog box is creating XPath expressions. The XPath Expression Builder allows you to build complex expression, that the default dialog boxes cannot create for you and offers easy access to the names of the fields in the data source, as well as to many of the built-in functions that are available when writing XPath expressions.
Using the XPath Expression BuilderThe XPath Expression Builder makes it very easy to create XPath expressions and even provides built-in IntelliSense for XPath. You can use the XPath Expression Builder to create the following.
- Complex sort expressions
- Complex filters
- Conditional expressions
- Formula columns
In the rest of this section we will describe how to build the first three types, and then the next section we will detail how to use the XPath Expression Builder with formula columns.
You can use the XPath Expression Builder to create XPath expressions that perform complex sort orders on data, as we show in the next procedure.
- Click on the chevron arrow in the upper right corner of the Data View to open the Common Data View Tasks action panel.
- Click on the Sort and Group option to open the Sort and Group dialog box.
- Select Add Sort Expression, which is the last field in the Available fields list box and click Add. This opens the Advanced Sort dialog box where you can create XPath expressions. When you are finished using the Advanced Sort dialog box, click OK twice.
Next we will use the XPath Expression builder to create advanced filters as follows.
- Click on the chevron arrow in the upper right corner of the Data View to open the Common Data View Tasks action panel.
- Click Filter, this will open the Filter Criteria dialog box.
- Select the checkbox Add XSLT Filtering; this enables the Edit button.
- Click Edit to open the Advanced Condition dialog box where you can create XPath expressions. When you are finished using the Advanced Condition dialog box, click OK twice.
You can perform XPath queries on all types of data sources, even when the data in a data source is not natively stored as XML, for example, the data in a SharePoint list or SQL database. This is possible because such data is first rendered as XML by the Data View infrastructure, before the XPath expressions are applied to the data. You should also take note that XPath sorting and filtering is performed on the entire data set that has been retrieved from the data source and loaded into memory. Therefore, for performance reasons, it may be best to define your sorting and filtering criteria on the data source than defining it on the Data View.
You can use the XPath Expression Builder to build expressions that specify conditions for when applying conditional formatting as follows.
- Click on the chevron arrow in the upper right corner of the Data View to open the Common Data View Tasks action panel.
- Click Conditional Formatting; this opens the Conditional Formatting task pane. The Conditional Formatting task pane shows all the existing conditions in the selected Data View.
- Click on the arrow next to an existing condition and choose Edit condition, this opens the Condition Criteria dialog box.
- Click the Advanced button to open the Advanced Condition dialog box that lets you create XPath expressions.
The next figure shows the XPath Expression Builder, in this particular instance the Advance Condition dialog box. The text field on the left, right below the caption Select a field to insert, shows a hierarchical representation of the data structure of the selected data source.
These so-called fields can be used within an XPath expression. If you double-click a field it is added to the upper right text box just below the Edit the XPath expression caption. Alternatively, you can drag and drop field to the Edit the XPath expression text field.
The Edit the XPath expression text field is intended to create the XPath expression you need and to make this as easy as possible. The Preview section of the screen, at the bottom, provides an up-to-date representation of live data after applying an XPath expression to that data. If you change something in the Edit the XPath expression text field this change is reflected immediately in the Preview section.
Another really nice feature of the XPath Expression Builder is that the Edit the XPath expression text field displays an IntelliSense list that contains all available XPath operators as well as the fields that are available within a given context.
The Select a function category drop down list offers the choice between different types of categories of XPath functions, like Most Recently Used, All, and Math/Number. If you select a category, the list box below the Select a function to insert caption is updated so that it contains all XPath functions that belong to the selected category. The XPath functions can also be used within XPath expressions.

We discussed how using the XPath Expression Builder we can create complex sort expressions, complex filters and conditional expressions. Next, we detail how to create formula columns.
Creating a formula columnIn this section, we will demonstrate how to create a formula column based on information found in different elements in an XML data source. Imagine, if you will, a mobile phone company that keeps track of the mobile minutes a customer uses and the price of one mobile minute. This information is stored in an XML file. The company knows how many mobile minutes are used, and the price of a mobile minute, but they want to create a Data View to display the total price of all mobile minutes used by customer.
In this example, you will create a formula column that displays the result of multiplying the mobile minutes by the price. When the formula column is created the mobile phone company can quickly and easily access the total amount of money they get from their customers.
We have created a sample XML file containing the mobile minutes and the price per minute per customer. If you want to follow this example, you should create this file yourself. The contents of the XML file called customers.xml are as follows.
<?xml version="1.0" encoding="utf-8"?><Customers>
<Customer Name="A">
<MobileMinute>5000</MobileMinute>
<PricePerMinute>0.25</PricePerMinute>
</Customer>
<Customer Name="B">
<MobileMinute>10000</MobileMinute>
<PricePerMinute>0.20</PricePerMinute>
</Customer>
<Customer Name="C">
<MobileMinute>15000</MobileMinute>
<PricePerMinute>0.15</PricePerMinute>
</Customer>
</Customers>
First, you have to add the customers.xml file as a data source. In section “Adding an XML File as a data source”, we have explained the steps you have to follow to import an XML file data source. The next procedure shows you how to create a Data View and add a formula column.
- In SharePoint Designer, go to a page where you want to add your Data View. In this example, this will be the default.aspx page of a test SharePoint site.
- Click Data View on the menu bar and select Insert Data View.
- Click customers.xml in the XML Files section of the Data Source Library task pane and select Show Data. This opens the Data Source Details task pane.
- Hold the CTRL key down, select Name, MobileMinute and PricePerMinute fields and then select Insert Selected Fields as > Multiple Item View.
- On the Data View Web Part, click the chevron in the upper right corner of the Data View to open the Common Data View Tasks action panel.
- Click Edit Columns. This opens the Edit Columns dialog box.
- Select Add Formula Column in the Available Fields list and click Add. This opens the XPath Expression Builder dialog box. This looks very similar to the Add Condition dialog box you saw in the previous section.
- In the Select a field to insert box, double-click the MobileMinute field to place it in the Edit the XPath expression box. If you want to insert the full path of the field, hold down the CTRL key while you double-click or drag the field.
- Place your cursor in the Edit the XPath expression box directly after the MobileMinute field and press the SpaceBar. This displays an IntelliSense list containing all available XPath operators. IntelliSense for XPath helps creating XPath expressions by providing a list of available fields or functions that are valid in the context of the expression. Double click the * operator and then double click PricePerMinute. The expression you have build will multiply the value contained in the MobileMinute field with the value in the PricePerMinute field.
- The final XPath expression looks like this: MobileMinute * PricePerMinute. In the Preview box you can see a preview of the results of the data in the formula column based on real data in the specified data source. Click OK in the XPath Expression Builder dialog box and click OK to close the Edit Columns dialog box.
- The middle of the SharePoint Designer screen shows a preview of the Data View Web Part. Here you will see a new column called MobileMinute * PricePerMinute. To change the name of column, you can select the name of the column header and type a new name, such as, Payment Due. You can alter the other column headings in a similar way, and by entering Customer to the right of A, SharePoint Designer will prefix the values in the Name field with Customer too.
- Save the page and browse to the default.aspx page of your SharePoint site that contains the Data View Web Part.


You may be saying to yourself that you can do these sorts of calculation using the calculated column in a list or a library, which is true, but remember by using the Data Source Library, you can access more data than that which is stored in SharePoint lists and library. If you have used the XPath query language in the past, you probably agree that it can be tricky to use. As a general trend, we notice that all sorts of commercial tools try to abstract the complexity of using XPath away by providing visual aids. A good example of such a tool created by Microsoft is the BizTalk mapper. You can now add the Data View Web Part and SharePoint Designer to the list of tools that make it easier to work with XPath.
Summary
The power of the Data View Web Part tends to be underestimated. We are sure you will not make the same mistake now you have read this article. It has been quite a journey and we hope you have tried out the various techniques we described. If you have not, remember that it is not too late! If you find it difficult at first, remember that Pablo Picasso once said, “I am always doing what I can not do, in order that I may learn how to do it”.
The article started with an introduction of the Data View Web Part and SharePoint Designer. Both tools might be new to you, and it typically takes some time getting used to the idea that you can use the Data View Web Part to aggregate and manage data.
In order to be able to aggregate and manage data, you will first need to define which data sources you want to use and how you can access these data sources. Therefore, we looked at importing and displaying data with the Data View Web Part. You saw that the Data Source Library plays a vital role in accessing data sources and you learned the kind of data sources accessible to the Data View Web Part, such as SharePoint lists, relational databases and XML files.
After demonstrating the basics of consuming data sources, you learned about more advanced topics. You saw that it is possible to connect to data sources located in other SharePoint sites. You also learned how to filter, sort, and group information displayed in the Data View Web Part. If you are interested in building sophisticated user interfaces, you were probably happy to learn about the possibilities of changing the Data View layout, generating test data, and previewing the result.
Sometimes you will be interested in creating read-only reports, so in this article you have learned how to create a data source as a view to accomplish this. At other times, you will also be interested in editing the data displayed by the Data View Web Part and you saw how to create a form to cater for this need. The article also provided you with a nice overview of the exact differences between Views and Forms.
It was interesting to explore the possibility of how to combine separate data sources using Linked data sources. We showed examples of a merged data view, an intersection of data, and a joined data view, a union of data.
The final part of the article was dedicated to the XPath Expression Builder. The XPath query language is a great language for retrieving data from XML files. In the past, the downside of using this language has been its complexity and its syntax that is rather difficult to read. The XPath Expression Builder offers a development environment that includes IntelliSense support, making development efforts using the XPath language easier.
When all is said and done, the most amazing thing about the Data View Web Part is its capability to build advanced user interfaces in a short amount of time. We would not want to go on record, stating that building Web Parts that aggregate and manage data within a SharePoint environment is a complex mission to undertake, but the boost of productivity that is offered by the Data View Web Part is a force to be reckoned with.