Wednesday 6 June 2007

SharePoint 2007 - Basic Printing page - listing of master / detail lists

Data Views are something which is quite standard in terms of SharePoint Designer, however, it gives you lots of flexibility, and I thought I'd bring this to the attention of those who still have not used it.

DataViews can satisfy a request which we get often is the ability to print information in SharePoint. The normal pages usually contain too many non-content items that simply make a printout of them too cluttered. Therefore we need to create a clean-sheet page (no navigation items etc), with information only.

For this example we have created two lists, one with Supplier names, and with the details of Contact Persons of each supplier. The contacts list uses a lookup of the Suppliers list, so that we have a master / detail link.

We will now create a information only page with just the merged details of the two lists.
Create a minimal master page
To do this we will create a minimal master page. I have tweaked the minimal master page even further to contain no controls at all (not even the username control). You can download the file from: Blank Master Page. We can either use SharePoint Designer to create this or you can actually save the page as minimal.master using Notepad and then upload it to the masterpage library (_catalogs/masterpage).

Create a new page from the master page
Using SharePoint Designer we then create a new page from the master page we have just uploaded.

Create a Linked DataSource
Click on the DataView menu and click Manage Data Sources. Scroll to the bottom of the Data Source Library until you find Linked Sources and click on Create a new Linked Source. Click on Configured Linked Source and choose the two lists you want to print information from, click next and choose Join the contents of the data sources.




Create custom content in the PlaceHolderMain
Click on the PlaceHolderMain click on the small arrow to bring up the Common Content Tasks, and click on create Custom Content. This will allow us to create content in this PlaceHolder.


Insert Data View
Open the Linked Data source which you have created above and click on Show Data. Choose the Fields you want to show, and drag them into the custom content area you have created in the previous step. You will now get a list of the items in your first list.

Merge the information from the two lists
Click on the first line (important that this you choose the first line so that we create a template). Right click > Insert > Row Below. This will create a new row for us to insert a new table containing the information of the second list. Place the cursor in the new line, and go to the Data Source Library again, scroll down to find the second list's information, choose the fields you want to populate and click on Insert Selected Fields As > Joined Subview. When you are prompted choose the column which is the link (lookup) between the two lists.



You can now play around with the table, format it as you please (merge cells as necessary for correct formatting), insert a new row below (after the details and put a horinzontal rule, etc. etc.).

Result

This example can be tweaked further to include three or more linked lists.
Remeber that if any of your lists contain divs or other html, you need to disable output escaping. Also, if you are going to export your page to a different SharePoint you need to edit your datasources to solve the GUID problem.