Question

I am trying to use the Data View Web Part in Sharepoint. There are many articles on the web related to populating it with data. My question is, what if the data source is empty? Is there a way to display a default message in this scenario?

Was it helpful?

Solution

You can do this in the XSL stylesheet, which is what SharePoint Designer does when you set the text to display if data source is empty.

    <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0" />
    <xsl:choose>
        <xsl:when test="$dvt_IsEmpty">
            <xsl:call-template name="dvt_1.empty" />
        </xsl:when>
        <xsl:otherwise><!-- Do stuff if not empty --></xsl:otherwise>

<xsl:template name="dvt_1.empty"><!-- Default template from SPD -->
    <xsl:variable name="dvt_ViewEmptyText">There are no items to show in this view.</xsl:variable>
    <table border="0" width="100%">
        <tr>
            <td class="ms-vb">
                <xsl:value-of select="$dvt_ViewEmptyText" />
            </td>
        </tr>
    </table>
</xsl:template>

OTHER TIPS

Go to the DataView properties, under the General tab at the bottom there is a field where you can type the message that you want to display if there n data displayed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top