SharePoint Use Cases

25 Nov, 2008

Displaying a number of items in a list - Part 2

Posted by: Toni Frankola In: SharePoint  Bookmark and Share

In Part 1 of this post I outlined a use case for using list items counter. In this post I will describe how you can create such a web part.

Prerequisites:

Step by step guide

  1. Open the page you want to customize with SharePoint Designer and insert a SharePoint Data View Control. (Click here to learn more.)
  2. If you want to list contents of the contacts list it will look like this:

  3. Right click on grid and select “Convert to XSLT Data View” option
  4. The first thing you will need to remove is table heading. From SPD open Source view of your page and look for HTML lines similar to ones below. Actual field names may vary for your list:
    <tr valign=”top”>

    <xsl:if test=”$dvt_1_automode = ‘1′” ddwrt:cf_ignore=”1″>

    <th class=”ms-vh width=”1%” nowrap=”nowrap”></th>

    </xsl:if><th class=”ms-vh nowrap=”nowrap”>Last Name</th>

    <th class=”ms-vh nowrap=”nowrap”>Modified By</th>

    <th class=”ms-vh nowrap=”nowrap”>Modified</th>

    </tr>

    You can comment or delete these lines from source code.

  5. Now you need to remove the actual values that are being displayed. The simplest way to do that is to look for xsl:for-each block. Replace the entire block with this simple code:
    <tr><td class=”ms-vb“>Total: <xsl:value-of select=”count($Rows)” /></td></tr>
  6. The above code will count all the nodes of your XML, and display only the count number accompanied with label “Total: “. Here is the preview of the result.

  7. For a web part that counts all the items in a list you do not need paging. Use Common Tasks to set paging to display all items.

The final result shown at figure below:

The technique described in this article can be used in various ways, and I will try to present some of these in a future article.




Comments

1 | Albert Buswell

July 16th, 2009 at 2:05 pm

Avatar

When I right click on the data view (any part, the grid, the header, etc.) I don’t see an option to convert to an xslt data view. I’m using Sharepoint Designer 2007 SP1.

2 | Toni Frankola

July 22nd, 2009 at 1:11 pm

Avatar

@Albert: It looks like this: http://2.bp.blogspot.com/_ZLr3wvXiUTE/RkQd-XgGMdI/AAAAAAAAAhI/SOWTxLqJ6_g/s1600-h/convert-to-xslt.jpg

You will have to position your mouse on the right spot to see it.

3 | Kevin Byrne Langlois

August 5th, 2009 at 5:19 pm

Avatar

Would it be possible to do the same with a library ? I tried with a form library with no success!

4 | Toni Frankola

October 11th, 2009 at 12:24 pm

Avatar

@Kevin: Sure, can you tell me what did you manage to do so far… and we can start from there…

Comment Form


About

Real-life use case and opinions about collaboration, CRM and web technologies and stuff by Toni Frankola. More...

Categories

All postings on this blog are provided "AS IS" with no warranties, and confer no rights. All entries in this blog are my opinion and don't necessarily reflect the opinion of my employer.