【问题标题】:Filtering based on dropdown in DVWP基于 DVWP 中的下拉列表进行过滤
【发布时间】:2013-01-17 06:35:52
【问题描述】:

我创建了一个 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>

这就是你要找的吗?

嗯,如果这有帮助,在我用来填充下拉列表的列表中,“年份”字段有一个内部名称 @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" />

【问题讨论】:

  • 如果我在下面的回答没有帮助,在列表的 DVWP 的 XSL(不是下拉列表的那个)中,您能否找到一个名为“dvt_1”(&lt;xsl:template name="dvt_1"&gt;)的模板一堆变量定义朝向模板的开头,并在此处提供这些变量定义?特别是,我正在寻找一个名为“行”的,但请提供它们。
  • 另外,您能否找到名为“dvt_1.rowview”的模板并提供包含年份的部分?像这样的东西:&lt;td class="ms-vb" style="width: 112px"&gt;&lt;xsl:value-of select="Year"/&gt;&lt;/td&gt;。我想仔细检查它用于 Year 字段的实际名称。由于您有 2 个 DVWP,因此这些模板可能具有后缀 _2 而不是 _1,因此请注意这一点。
  • 感谢您添加 XSL。您能否提供我在第二条评论中要求的部分,来自“dvt_1.rowview”?还有一件事——在这个 DVWP 的 XSLT 开头应该有一堆 &lt;xsl:param&gt; 元素。可以发一下吗?
  • 当我提到&lt;xsl:param&gt; 时,我指的是在xsl:stylesheet 行之后不久出现的实际xsl:param 元素,而不是xsl:with-param。如果您将整个 .aspx 的内容发布在 codebin.org 上,也许这会更容易。你能做到吗,还是里面有机密的东西?
  • 这里:codebin

标签: sharepoint xslt filter dataviewwebpart


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    如果您的参数名称称为param1,那么我相信您的下拉菜单需要将一个名为“param1”的查询字符串参数传递到 URL 中,而不是“year”。您可以尝试将选择标签修改为这样吗?:

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

    【讨论】:

    • 不,这不起作用。让我感到困惑的是,因为我在页面上有 2 个 DVWP,并且因为我对 DVWP 使用了不同的列表,所以我不能在其他 DVWP 中使用过滤器参数或列表字段。我遵循的大多数教程只处理一个页面上的 1 个 DVWP。
    • 感谢您的所有帮助。我刚刚注意到(感谢我的一位同事)作为计算列的 Year 是一个字符串。因此,对于 2013 年,它将其存储为 2,013,因此我无法正确过滤 DVWP。我使用=TEXT(([columnname], "yyyy") 而不是YEAR([colname]),一切正常。
    • 优秀。感谢您的反馈。那么&lt;select&gt;标签的最终值是多少,&lt;xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/&gt;毕竟不需要修改吗?
    • &lt;select&gt; 标签的值与我之前发布的相同。 &lt;xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/&gt; 确实不需要修改,但它在调试 DVWP 中发挥了重要作用。所以也谢谢你。只是 OOB 过滤技巧起作用了。 :)
    猜你喜欢
    • 2016-04-23
    • 1970-01-01
    • 2018-10-04
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 2018-06-12
    相关资源
    最近更新 更多