根据DVWP中的下拉列表进行过滤

时间:2013-01-17 06:35:53

标签: sharepoint xslt filter dataviewwebpart

我创建了一个DVWP下拉列表,用于过滤我使用DVWP显示的列表。我将年份列表设置为下拉DVWP数据源,并选择一年,我想过滤列表DVWP以显示按年度过滤的项目。

下拉菜单:
<select name="ID" size="1" onchange="document.location.href='http://server/site.aspx' + '?' + 'year' + '=' + this.options[selectedIndex].value">

我添加了一个QueryString参数param1,它将Year的值从此​​下拉列表中取出,并列出DVWP列表。在DVWP列表中,我添加了一个过滤条件:Year equals [Param1]。注意:这里的年份是一个计算列,它从日期字段中获取年份。 我的问题是,即使下拉菜单在选择一个值后回复,也不会被过滤掉。我做错了什么?我一直绞尽脑汁,但无论我尝试什么,我都无法工作。请帮忙。

<xsl:template name="dvt_1">
            <xsl:variable name="dvt_StyleName">Table</xsl:variable>
            <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
            <xsl:variable name="dvt_FieldNameNoAtSign" select="substring-after($dvt_filterfield, '@')" />
            <xsl:variable name="dvt_FilteredRowsText" select="$Rows[.=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(.,'T'))]" />
            <xsl:variable name="dvt_FilteredRows" select="$Rows[normalize-space(*[name()=$dvt_filterfield])=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(normalize-space(*[name()=$dvt_filterfield]),'T'))]" />
            <xsl:variable name="dvt_FilteredRowsAttr" select="$Rows[normalize-space(@*[name()=$dvt_FieldNameNoAtSign])=$dvt_filterval or ($dvt_filtertype='date' and substring-before($dvt_filterval,'T') = substring-before(normalize-space(@*[name()=$dvt_FieldNameNoAtSign]),'T'))]" />
            <xsl:variable name="dvt_RowCount">
                <xsl:choose>
                    <xsl:when test="$dvt_adhocfiltermode != 'query' and $dvt_filterfield">
                        <xsl:choose>
                            <xsl:when test="starts-with($dvt_filterfield, '@')"><xsl:value-of select="count($dvt_FilteredRowsAttr)" /></xsl:when>
                            <xsl:when test="$dvt_filterfield = '.'"><xsl:value-of select="count($dvt_FilteredRowsText)" /></xsl:when>
                            <xsl:otherwise><xsl:value-of select="count($dvt_FilteredRows)" /></xsl:otherwise>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise><xsl:value-of select="count($Rows)" /></xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="RowLimit" select="10" />
            <xsl:variable name="FirstRow" select="$dvt_firstrow" />
            <xsl:variable name="LastRow">
                <xsl:choose>
                    <xsl:when test="($FirstRow + $RowLimit - 1) &gt; $dvt_RowCount"><xsl:value-of select="$dvt_RowCount" /></xsl:when>
                    <xsl:otherwise><xsl:value-of select="$FirstRow + $RowLimit - 1" /></xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0 or $RowLimit = 0" />
            <xsl:variable name="dvt_IsEmpty" select="$dvt_RowCount = 0"/>
            <xsl:call-template name="dvt_1.toolbar">
                <xsl:with-param name="Rows" select="$Rows" />
            </xsl:call-template>
            <xsl:choose>
                <xsl:when test="$dvt_IsEmpty">
                    <xsl:call-template name="dvt_1.empty"/>
        </xsl:when>

这是你在找什么?

嗯,如果这有帮助,在我用来填充下拉列表的列表中,'Year'字段有一个内部名称@Title。这会与此有关吗?
<xsl:template name="dvt_1.rowview"> <option> <xsl:value-of select="@Title" /> </option> </xsl:template> 。但它也有@Year,所以不确定哪个是哪个。
<td class="ms-vb"> <xsl:value-of select="@Year"/> </td>
哎呀,抱歉让人困惑。第二个@Year是我创建的计算列。
更新2:您要求的代码:

<td class="ms-toolbar" nowrap="nowrap">
                                <xsl:call-template name="dvt.filterfield">
                                    <xsl:with-param name="fieldname">@Year</xsl:with-param>

                                    <xsl:with-param name="fieldtitle">Year</xsl:with-param>

                                    <xsl:with-param name="Rows" select="$Rows" />

                                    <xsl:with-param name="fieldtype">text</xsl:with-param>

                                </xsl:call-template>

为dvwp创建了类似的东西:
<xsl:param name="ListID">{6889CA36-79AC-4FA8-9F0A-C013C944B3C5}</xsl:param> <xsl:param name="Param1" />

2 个答案:

答案 0 :(得分:1)

我刚刚注意到(感谢我的一位同事),Year这是一个计算列,是一个字符串。因此,对于2013年,它将其存储为2,013,因为我无法正确过滤DVWP。我使用=TEXT(([columnname], "yyyy")代替YEAR([colname]),一切正常。

答案 1 :(得分:0)

如果您的参数名称被称为param1,那么我相信您的下拉列表需要将名为“param1”的查询字符串参数传递到URL而不是“year”。你能尝试修改那个选择标签吗?:

<select name="ID" size="1"
  onchange="document.location.href='http://server/site.aspx?param1=' 
  + this.options[selectedIndex].value">
相关问题