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:
- Microsoft Office SharePoint Designer 2007
- One contacts list (or any other list) with some sample data
- Basic knowledge of HTML and XSLT
Step by step guide
- Open the page you want to customize with SharePoint Designer and insert a SharePoint Data View Control. (Click here to learn more.)
- If you want to list contents of the contacts list it will look like this:
- Right click on grid and select “Convert to XSLT Data View” option
- 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.
- 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> - 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 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.
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.
4 Responses
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.
@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.
Would it be possible to do the same with a library ? I tried with a form library with no success!
@Kevin: Sure, can you tell me what did you manage to do so far… and we can start from there…
Comments are closed.