如果Sharepoint中的数据视图Web部件没有数据,如何显示默认文本?

时间:2008-12-12 12:14:28

标签: sharepoint web-parts dataview

我正在尝试在Sharepoint中使用数据视图Web部件。网上有很多与填充数据相关的文章。我的问题是,如果数据源是空的怎么办?有没有办法在这种情况下显示默认消息?

2 个答案:

答案 0 :(得分:3)

您可以在XSL样式表中执行此操作,这是SharePoint Designer在您将数据源设置为空时显示的内容。

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

答案 1 :(得分:1)

转到DataView属性,在底部的“常规”选项卡下,有一个字段,您可以在其中键入要显示的数据,如果有数据显示。