Sunday, November 11, 2012

Numbering Items (Descending as well) In DVWP

Having the default item ID from SharePoint can be a little bit tricky – if you erase an item, you lose the sequential order, or if you are getting the items from a number of lists you will have duplicated ID’s.
So, if the ID is not important, and you only need to number it, you can use the position (add +1 so it will start from 1 instead of 0), For example (in the rowview):

<xsl:value-of select="position()+1"/>

But, if the order should be descending you can use the number of rows and the position. For example:

In the call to rowview:
<xsl:call-template name="dvt_1.rowview">
    <xsl:with-param name="Rows" select="$Rows" />

In the rowview:

<xsl:template name="dvt_1.rowview">
    <xsl:param name="Rows" />
    <xsl:value-of select="count($Rows) - position() +1"/>

It will even work with paging (will preserve the number from previous page and not start over from the current page).

No comments:

Post a Comment