Rolling Up Content in SharePoint Using the Data View Web Part (DVWP)

In a recent post, I pointed out a way to roll up calendar entries using the Data View Web Part (DVWP).  That approach works if you have a fixed set of calendars for which you’d like to display the roll-up.  But what if you’d like the roll-up to be dynamic, i.e., have it display events for any new calendars that are created below a certain place in your site hierarchy?

Well, the way to do this is still using the trusty old DVWP (how could we live without it?!?!?!).  There are several DataSourceModes that are available in the DVWP that aren’t exposed in the SharePoint Designer interface.  (ListofLists, Webs, and CrossList modes. ListsofLists and Webs modes show the collection of lists and the collection of subsites for a given site.)  The mode that we need here is CrossList, which allows us to display items across lists below a certain point in the site hierarchy.

Here are the basic steps:

  • Set up your DVWP so that it has the display that you want for all of the lists, but do it the way you normally would for a single list. (i.e., pick one of your lists and make everything pretty for it alone.)
  • Now, if you aren’t already there, switch to code view, and in the code for your DVWP find the DataSourceMode property and change it from List to CrossList.
  • Right after that property, you’ll see the SelectCommand property.  This is the code that tells the DVWP what query to use for the SPDataSource.  Add <Webs Scope=’Recursive’></Webs> immediately after the opening quote, and leave the rest of the SelectCommand as it is.
  • Immediately after this section, you will see values for <SelectParameters>, <DeleteParameters>, <UpdateParameters>, and <InsertParameters>.  You can delete all of these, as they are not relevant to the CrossList mode.
  • Down a little further, you’ll see the <ParameterBindings> section.  Make sure that the line <ParameterBinding Name=”WebURL” Location=”None” DefaultValue=”/sitename/subsitename/”/> reflects the “root” from which you’d like the rollup to work.  (i.e., the DVWP will shown all items from this site and below — That’s what the Recursive scope you put into the SelectCommand does.)
  • Lastly, go a little further down and make sure that the path in the line <xsl:param name=”WebURL”>/sitename/subsitename/</xsl:param> matches the one above.
  • You can also remove any references to ListIDs, as they aren’t relevant.

If you’ve done everything right, you should see items returned by the DVWP that come from all of the like-structured lists below the site you’ve indicated.  You can continue to make formatting changes in the XSL, but to me it seems easier to get it at least close to right before you switch to CrossList mode.

NOTE: I posted an update to this post on September 21, 2008.  You should read that followup in conjunction with this post.

16 Comments

  1. I tried using this. It looks like it is working (because on the Data Source Details I see Row [1/431] but I do not see any rows on the page. My code looks like this (the subsite that will act as root is /labs). Please let me know where I went wrong.
     
     <SharePoint:SPDataSource runat="server" DataSourceMode="CrossList" UseInternalName="true" selectcommand="&lt;Webs Scope=&quot;Recursive&quot;&gt;&lt;/Webs&gt;" id="dataformwebpart1">
     </SharePoint:SPDataSource>
     
     
      <xsl:param name="dvt_apos">'</xsl:param>
     <xsl:param name="WebURL">/labs/</xsl:param>
    <parameterbindings>
      <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
      <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
      <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
      <ParameterBinding Name="WebURL" Location="None" DefaultValue="/labs/"/>
     </parameterbindings>
     
     
     
     
    Reply
  2. Hi Marc,

    I am trying to use the Data View web part to pull back all documents with a certain Content Type but failed to make it to work.

    Have you tried the CrossList method to pull back documents??

    Every time I change the DataSourceMode=”List” to DataSourceMode=”CrossList”, it displaying blank rows.

    If you can share some information, that will be great!

    Thank you!

    Reply
  3. yh_rose:

    I’ve got quite a few posts about using the DataSourceMode=”Crosslist”. Try searching (there’s a search box on the right panel) for Crosslist and take a look. I’d be happy to answer any further questions as you have them.

    If you aren’t seeing anything in your DVWP, check two things:
    1) Are *all* of the columns you want to display in *all* of the items you want to display?
    2) Are the columns you want to display specified in your CAML?

    M.

    Reply
  4. Hi Marc

    Thanks for the info on crosslist DVWP again, but for me the WebURL doesnt seem to effect which site(s) my list items are taken from. I have it in my parameter bindings and as an xsl:param matching. The SPDataSource is Crosslist and Webs are set to recursive. Anything else i could be missing?

    David

    Reply
  5. Hi Marc,

    Your post seems to be very interesting and using your blog as the key reference for my work.
    I got stuck after changing the datasource to “crosslist” no data is rendering. I have attached the code for your review.

    Not sure why it is not working. Some more queries:
    inside the selectcommand=””

    if I add viewfields it giving this error “The server returned a non-specific error when trying to get data from the data source. Check the format and content of your query and try again. If the problem persists, contact the server administrator.”

    Also I am not clear in these following (could you please explain what these weburl is and how to use it with a realtime sample)

    /mysitename/

    This is what I have

    @ID,ID;@ContentType,Content Type;@Title,Title;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;@ItemChildCount,Item Child Count;@FolderChildCount,Folder Child Count;@Predecessors,Predecessors;@Priority,Priority;@Status,Status;@PercentComplete,% Complete;@AssignedTo,Assigned To;@TaskGroup,Task Group;@Body,Description;@StartDate,Start Date;@DueDate,Due Date;

    /mysitename/

    1

    0

    Table

    LinkTitle
    Priority
    Status
    % Complete
    Due Date

    ms-alternating

    There are no items to show in this view.

    1


    javascript: ;
    Start

     

    javascript: history.back();


     


     


    javascript: ;

    Reply
  6. Marc,

    Sorry to dredge up an old post, but it is relavent to something I am working on. I am fairly certain that my query information is correct, but I really need a full example of an xsl stylesheet that works. Mine does not appear to work at all :(

    Reply
    • Daniel:

      The stylesheet can really be anything you want. First set things up the way you want them to look with one list, then switch to Crosslist mode. Also check this post for more info.

      M.

      Reply
  7. hi,
    as mentioned above as soon as i added the viewfields tag in the select command .i get the xslt errors regarding querying.and without and viewfields the webpart shows only id field values.please help me out here……….

    Reply
  8. Hi,

    I am using CrossList in DVWP to display the latest status for a project list in each subsite. I wanted to limit to the items from each subsite to just one (the latest status). I tried using the RowLimit in the Selectcommand but it output only one item overall instead of per site. I sorted the lists by project name and id (descending), then used and NameChanged function in the dti_rowview template to hide the additional rows from each subsite, but when doing a column sorting on some field, the hidden rows are also sorted resulting in unwanted rows (i.e. not the latest status) being displayed.

    Is there a way to limit the rows per site to just one (the latest one)?

    Reply
    • Goh:

      I don’t think so. This may be a case where using script would be better, at least from a filtering perspective. You’d need to make a call for the content from each underlying list, though, which would be slower. DVWPs are great because they are evaluated on the server and only the resulting content comes down to the browser.

      You could probably use NameChanged, though and just change the initial sort so that you sorted by descending date per ID, and that ought to work?

      M.

      Reply

Leave a Reply