Tuesday, March 16, 2010

Building a Rollup List in SharePoint



INTRODUCTION

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.



STEPS
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:

                <SharePoint:SPDataSource runat="server"

                 DataSourceMode="List"
                 SelectCommand="<View></View>"
                  id="DataSource1" >
                 <SelectParameters>
                 <WebPartPages:DataFormParameter
                 Name="ListID"
                 ParameterKey="ListID"
                 PropertyName="ParameterValues"
                 DefaultValue="GGGGGGGG-HHHH-CCCC-JJJJ-KKKKKKKK1111" />
                </SelectParameters>
               </SharePoint:SPDataSource>
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:

            DataSourceMode="CrossList"
                             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: gpatel@kieferconsulting.com
__________________________________________________________________

ABOUT ME

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/

2 comments:

  1. How do you actually display the list item from subsite to this root site roll up list. Can you give more instructions on this? Thanks.

    ReplyDelete
  2. In SharePoint, these are the steps you could implement to be SharePoint experts. Also find best SharePoint 2013 Certification Training in your locality at StaygreenAcademy.com

    ReplyDelete