Most enterprises store related data in different locations. For example, product information is stored in an .xml file called products.xml, but information about product categories is stored in another .xml file called categories.xml. The two data sources are related to one another by a field called CategoryID.
With Microsoft Office SharePoint Designer 2007, you can easily link data sources that contain related data and then create a single Data View that displays data from those linked data sources. You can even link different types of data sources — for example, you can link an XML file to an SQL database.
When you link data sources, you create a single data source that appears in the Data Source Library with all your other data sources. Creating a view of this linked data source is much like creating any other Data View. And after you create a Data View of a linked data source, you can filter, sort, group, format, or do anything with that Data View that you can do with any other Data View.
This article shows you how to create two sample XML files to use as data sources, how to link the two data sources, and then how to create a single Data View that displays data from both data sources. This articles uses an .xml file as a data source so that you can easily create the data source and follow along. However, the following procedure works with any data source, including SQL databases.
Important This article discusses creating Data Views in SharePoint sites that are located on servers running Microsoft Windows SharePoint Services 3.0. Not all functionality may be available if your site is not located on a server running Windows SharePoint Services 3.0.
To learn more about Data Views, see Create a Data View.
Northwind Traders maintains their product list in XML format. They also maintain a category list. The two lists are associated by a field called CategoryID. By linking these two XML files and creating a single Data View, you can easily create a list of products that are organized by product category.
If you already created products.xml for Create a Data View, skip to the next section.
<?xml version="1.0" encoding="utf-8"?>
<ProductsRoot>
<Products>
<ProductID>1</ProductID>
<ProductName>Chai</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>10 boxes x 20 bags</QuantityPerUnit>
<UnitPrice>18</UnitPrice>
<UnitsInStock>39</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>10</ReorderLevel>
<Discontinued>0</Discontinued>
</Products>
<Products>
<ProductID>2</ProductID>
<ProductName>Chang</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>1</CategoryID>
<QuantityPerUnit>24 - 12 oz bottles</QuantityPerUnit>
<UnitPrice>19</UnitPrice>
<UnitsInStock>17</UnitsInStock>
<UnitsOnOrder>40</UnitsOnOrder>
<ReorderLevel>25</ReorderLevel>
<Discontinued>0</Discontinued>
</Products>
<Products>
<ProductID>3</ProductID>
<ProductName>Aniseed Syrup</ProductName>
<SupplierID>1</SupplierID>
<CategoryID>2</CategoryID>
<QuantityPerUnit>12 - 550 ml bottles</QuantityPerUnit>
<UnitPrice>10</UnitPrice>
<UnitsInStock>13</UnitsInStock>
<UnitsOnOrder>70</UnitsOnOrder>
<ReorderLevel>25</ReorderLevel>
<Discontinued>0</Discontinued>
</Products>
<Products>
<ProductID>4</ProductID>
<ProductName>Chef Anton's Cajun Seasoning</ProductName>
<SupplierID>2</SupplierID>
<CategoryID>2</CategoryID>
<QuantityPerUnit>48 - 6 oz jars</QuantityPerUnit>
<UnitPrice>22</UnitPrice>
<UnitsInStock>53</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>0</ReorderLevel>
<Discontinued>0</Discontinued>
</Products>
<Products>
<ProductID>5</ProductID>
<ProductName>Chef Anton's Gumbo Mix</ProductName>
<SupplierID>2</SupplierID>
<CategoryID>2</CategoryID>
<QuantityPerUnit>36 boxes</QuantityPerUnit>
<UnitPrice>21.35</UnitPrice>
<UnitsInStock>0</UnitsInStock>
<UnitsOnOrder>0</UnitsOnOrder>
<ReorderLevel>0</ReorderLevel>
<Discontinued>1</Discontinued>
</Products>
</ProductsRoot>
<?xml version="1.0" encoding="utf-8"?>
<CategoriesRoot>
<Categories>
<CategoryID>1</CategoryID>
<CategoryName>Beverages</CategoryName>
<Description>Soft drinks, coffees, teas, beer, and ale</Description>
</Categories>
<Categories>
<CategoryID>2</CategoryID>
<CategoryName>Condiments</CategoryName>
<Description>Sweet and savory sauces, relishes, spreads, and seasonings</Description>
</Categories>
<Categories>
<CategoryID>3</CategoryID>
<CategoryName>Confections</CategoryName>
<Description>Desserts, candies, sweetbreads</Description>
</Categories>
<Categories>
<CategoryID>4</CategoryID>
<CategoryName>Dairy Products</CategoryName>
<Description>Cheeses</Description>
</Categories>
<Categories>
<CategoryID>5</CategoryID>
<CategoryName>Grains/Cereals</CategoryName>
<Description>Breads, crackers, pasta, and cereal</Description>
</Categories>
<Categories>
<CategoryID>6</CategoryID>
<CategoryName>Meat/Poultry</CategoryName>
<Description>Prepared meats</Description>
</Categories>
<Categories>
<CategoryID>7</CategoryID>
<CategoryName>Produce</CategoryName>
<Description>Dried fruit and bean curd</Description>
</Categories>
<Categories>
<CategoryID>8</CategoryID>
<CategoryName>Seafood</CategoryName>
<Description>Seaweed and fish</Description>
</Categories>
</CategoriesRoot>
Before you can create a Data View that displays data from multiple sources, you must first link the data sources by using the Data Source Library. You want to create a list of products that are organized by product category, so you need to create a data source that links the products.xml file to the categories.xml file.
You have two options: merge or join. You merge data when you have different data sources with the same fields that you want to merge into a single data source. You join data when you have two different data sources that have a field in common that associates one data source with another data source. Because products.xml and categories.xml are two different data sources with the CategoryID field in common, you want to join the two data sources.
In the Data Source Library, under Linked sources, you can see your new linked data source.
Now that you have linked the data sources, you can create a Data View that displays data from the linked data source by using the Data Source Details task pane.
You want to create a Data View of the product list that is organized by product category. For each category in categories.xml, you can show the products in each category from products.xml.
Because you want to create a Data View that displays each product by category, you first want to create a view of categories.xml.
Data Views are based on Microsoft ASP.NET 2.0 technology. To create a Data View, you must start with an ASP.NET page (.aspx file). In this example, you will create a new ASP.NET page and then insert a Data View into the page.
A new page with a FORM tag opens.
An empty Data View is displayed on the page, and the Data Source Library task pane opens.
Now that you have inserted the Data View, you are ready to add the data.
You first want to create a Data View of categories.xml.
Note Single Item View displays a single record in a Data View. Multiple Item View displays multiple records, with the fields in columns and headings for each column.
The fields that you selected in the Data Source Details task pane now appear in the Data View.
In the next step, you will create a new column that displays a subview (a Data View that appears inside a cell of another Data View) of the data in products.xml.
A joined subview is a subview of a data source that is joined to another data source by a common field. In the next step, you will link the CategoryID field in categories.xml to the CategoryID field in products.xml.
The fields that you selected in the Data Source Details task pane now appear in the new column. Because the CategoryID fields between the two sources are linked, only the beverage products appear in the Beverages list, only condiments appear in the Condiments list, and so on.
Data Views are powerful, fully customizable views of live data sources. After you create a Data View of a linked data source, you can customize that Data View the same as any other Data View. Now that you have learned how to create a single Data View that displays data from multiple sources, you might want to learn how to: