Question

I have created a DVWP dropdown for filtering a list which I've shown using a DVWP. I've set an year list as the dropdown DVWP data source and on selecting a year, i wanna filter the list DVWP to show the items filtered by year.

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

I've added a QueryString parameter param1 which takes its value from Year to this dropdown as well as the list DVWP. In the list DVWP, I've added a filter condition which is: Year equals [Param1]. Note: Year here is a calculated column which gets year from a date field.
My question is even though the dropdown gets post back after selecting a value, it doesn't get filtered. What have I done wrong in this? I've been racking my brains on this but I can't get this to work no matter what I try. Please help.

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

Is this what you were looking for?

Umm, if this helps, in the list that I'm using to populate the dropdown, the 'Year' field has an internal name @Title. Would that have something to do with this?
<xsl:template name="dvt_1.rowview"> <option> <xsl:value-of select="@Title" /> </option> </xsl:template> . But it also has @Year, so not sure which is which.
<td class="ms-vb"> <xsl:value-of select="@Year"/> </td>
Oops, sorry for confusing. The 2nd @Year is the calculated column which I'd created.
UPDATE 2: The code you'd requested:

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

Something like this has been created for both the dvwp's:
<xsl:param name="ListID">{6889CA36-79AC-4FA8-9F0A-C013C944B3C5}</xsl:param> <xsl:param name="Param1" />

Était-ce utile?

La solution

I just noticed(thanks to a colleague of mine) that Year which is a calculated column is as a string. So, for 2013, it was storing it as 2,013 because of which I couldn't filter the DVWP properly. I used =TEXT(([columnname], "yyyy") instead of YEAR([colname]) and everything worked fine.

Autres conseils

If your parameter name is called param1, then I believe your dropdown will need to pass a query string parameter called "param1" into the URL instead of "year". Could you try modifying that select tag to be like this?:

<select name="ID" size="1"
  onchange="document.location.href='http://server/site.aspx?param1=' 
  + this.options[selectedIndex].value">
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top