SharePoint Use Cases

  • Home
  • About
  • Our Tools
  • Contact me
SharePoint

Displaying a number of items in a list – Part 2

Toni Frankola - November 25, 2008

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

  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.

Tags | contacts, count items, use cases
 0
Share Now

Toni Frankola

Entrepreneur, IT consultant, speaker, blogger, and geek. Co-founder of syskit.com.

You Might Also Like

SharePoint

Ready Steady SharePoint!

May 16, 2008
SharePoint

Displaying a number of items in a list

November 24, 2008
Misc

Using Microsoft CRM to distribute corporate Christmas gifts

December 1, 2008
SharePoint

Use case: Integrating SharePoint with LOB applications

February 16, 2009

4 Responses

  • Albert Buswell July 16, 2009 at 2:05 pm

    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.

  • Toni Frankola July 22, 2009 at 1:11 pm

    @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.

  • Kevin Byrne Langlois August 5, 2009 at 5:19 pm

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

  • Toni Frankola October 11, 2009 at 12:24 pm

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

  • Comments are closed.

    Previous Post Displaying a number of items in a list
    Next Post Using Microsoft CRM to distribute corporate Christmas gifts

    Archives

    • December 2021 (1)
    • June 2021 (1)
    • January 2021 (1)
    • July 2019 (1)
    • June 2019 (2)
    • March 2019 (1)
    • February 2019 (3)
    • October 2018 (2)
    • August 2018 (2)
    • June 2018 (1)
    • April 2018 (1)
    • February 2018 (1)
    • January 2018 (1)
    • June 2017 (1)
    • April 2017 (1)
    • February 2017 (1)
    • November 2016 (2)
    • August 2016 (1)
    • July 2016 (2)
    • March 2016 (1)
    • February 2016 (2)
    • January 2016 (1)
    • November 2015 (2)
    • December 2014 (1)
    • November 2014 (2)
    • July 2014 (2)
    • June 2014 (2)
    • May 2014 (1)
    • April 2014 (2)
    • March 2014 (1)
    • February 2014 (4)
    • January 2014 (2)
    • December 2013 (1)
    • September 2013 (1)
    • July 2013 (1)
    • June 2013 (1)
    • May 2013 (1)
    • April 2013 (3)
    • February 2013 (1)
    • December 2012 (1)
    • November 2012 (1)
    • September 2012 (1)
    • August 2012 (1)
    • July 2012 (2)
    • June 2012 (4)
    • April 2012 (1)
    • February 2012 (1)
    • January 2012 (1)
    • November 2011 (2)
    • October 2011 (2)
    • September 2011 (2)
    • July 2011 (3)
    • May 2011 (2)
    • April 2011 (1)
    • March 2011 (4)
    • February 2011 (3)
    • January 2011 (4)
    • December 2010 (4)
    • November 2010 (3)
    • October 2010 (3)
    • September 2010 (4)
    • August 2010 (1)
    • July 2010 (4)
    • May 2010 (2)
    • April 2010 (2)
    • March 2010 (3)
    • January 2010 (2)
    • December 2009 (3)
    • November 2009 (5)
    • October 2009 (2)
    • August 2009 (7)
    • July 2009 (3)
    • June 2009 (4)
    • May 2009 (3)
    • April 2009 (5)
    • March 2009 (8)
    • February 2009 (5)
    • January 2009 (8)
    • December 2008 (9)
    • November 2008 (8)
    • October 2008 (7)
    • September 2008 (4)
    • August 2008 (6)
    • July 2008 (5)
    • June 2008 (3)
    • May 2008 (4)
    • April 2008 (6)
    • March 2008 (4)
    • February 2008 (3)
    • January 2008 (6)
    • December 2007 (1)
    • November 2007 (3)
    • October 2007 (3)
    • September 2007 (2)
    • August 2007 (1)
    • July 2007 (12)
    • June 2007 (2)
    • May 2007 (3)

    Connect Us

    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.

    • Home
    • About
    • Our Tools
    • Contact me

    Copyright (c) Toni Frankola 2008. - 2019.