SharePoint–Data View Webpart Show Total Items in a list

There are times when I want to show a distinct dashboard style rollup of items in a list which match certain conditions.  There isn’t a lot of documentation online on XPath expressions for SharePoint Data View webparts.  Here is sample code to calculate the count of rows in a list.  Be careful to choose the right column to count so that you are guaranteed to get the total you expect.

I have included styling as an example because, why wouldn’t we style the results?

<style type=”text/css”>
.DVRow {
font:normal normal bold 20px Calibri;
<td class=”DVRow”>

<asp:Label runat=”server” id=”ff1{$Pos}” text=”{count(/dsQueryResponse/Rows/Row/@Title)}” __designer:bind=”{ddwrt:DataBind('u', concat('ff1',$Pos), 'Text','','ID',ddwrt:EscapeDelims(string(@ID)),'count(/dsQueryResponse/Rows/Row/@Title')}” />

Pay close attention to the XPath formula: count(<a>/dsQueryResponse/Rows/Row/@Title) as this performs the sum of the rows in the list.


Popular posts from this blog

SharePoint Designer 2013 Approval Workflow with Comments

SharePoint Search - Content Processing Pipeline Failed to Process the Item

Change SharePoint server hostname and Web Application Names