views:

766

answers:

1

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?

+3  A: 

Hello,

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>
Bjørn Furuknap