A frequent challenge for me in SharePoint is finding a way to combine multiple SharePoint lists at the root level site and then performing different operations on that “rolled up” list. Third-party web parts sometimes help, but budget constraints often prevent us from buying our way out of this problem. After some online research, I found an easy way to write my own code to roll up lists.
To display items across lists, you can use Data View Web Part (DVWP). The DVWP has some DataSourceModes you may not be aware of, including Webs, ListofLists, and CrossList. For example, for a given site, the Webs mode shows the collection of subsites, and the ListofLists mode shows the collection of lists. In my example below, I use the CrossList mode to combine items from multiple lists across the site hierarchy. This solution works in both SharePoint 2007 and SharePoint 2010.
Below are the basic steps necessary to use the CrossList mode:
1. Open SharePoint Designer, and open the page where you want the rolled up list to be displayed.
2. Insert the Data View Web Part on the page.
3. Select the list that you want to use as a data source for the DVWP. This is the list that you want to roll up across the site hierarchy.
4. Customize the display of DVWP such as number of columns, layout, and so on.
5. Switch to the code view and in the code find the DataSourceMode property in SPDataSource for your DVWP. Here is the sample SPDataSource of DVWP:
6. Change the value of the DataSourceMode property from List to CrossList.
7. After that, go to the SelectCommand Property. This is the property that we use to set a query for the SPDataSource of DVWP.
8. Add <Webs Scope='Recursive'></Webs> immediately after the opening quote and leave the rest of the Selectcommand as it is:
SelectCommand="<Webs Scope='Recursive'></Webs ><View></View>"
Here, the Webs element defines the scope of the query.
Note: You can use CAML query to customize the Selectcommand to filter the DVWP.
9. Immediately after Selectcommand, you will see <SelectParameters>, <DeleteParameters> and <UpdateParameters>. Delete these as they are not necessary for the CrossList mode.
10. Go to <ParameterBinding> section.
11. Find the line <ParameterBinding Name="ListID" Location="None" />. Remove the DafaultValue property; it is irrelevant in this mode.
12. Check the line <ParameterBinding Name=”WebURL” Location=”None” DefaultValue=”/sitename/subsitename/”/>.
13. Make sure that the DefaultValue points to the “root” site as from where you would like the rollup to work.
14. Now save the page and test it in your browser.
I hope this gives you some ideas for using the Data View Web Part. Happy coding! Email me if you have any questions: email@example.com
Gatika Patel is a Software Developer at Kiefer Consulting. She specializes in .NET and SharePoint application development, software testing, database management, and architecture planning. She is a Microsoft Certified Profession Developer who earned her M.S. in Software Engineering from San Jose State University and her Bachelor's degree in Information Technology from the Nirma Institute of Technology in India. Her current consulting assignments include various large projects for the State of California.
Kiefer Consulting, Inc. is a trusted leader in .NET application development and California’s leader in State Government SharePoint deployments, providing real business solutions using Microsoft .NET echnologies. With a 22 year track record of business success, the firm has experience ranging from the irst .NET releases all the way to legacy mainframe systems. Kiefer consultants are experts in the technologies they deploy, so clients always get best value solutions that balance Industry Best Practices and new technologies. Register now for Kiefer’s 2010 events and Edunars℠: http://www.kieferconsulting.com/