2

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

Akhoy
  • 502
  • 1
  • 13
  • 24
  • If my answer below doesn't help, in the XSL for the List's DVWP (not the one for the dropdown) could you locate a template with the name "dvt_1" (``) with a bunch of variable definitions toward the beginning of the template, and provide those variable definitions here? Particularly, I'm looking for one called "Rows", but please provide the bunch of them. – JLRishe Jan 17 '13 at 07:36
  • Also, could you locate the template called "dvt_1.rowview" and provide the part of that that includes the year? Something like this: ``. I want to double-check the actual name it is using for the Year field. There's a chance these templates could have the suffix _2 instead of _1 since you have 2 DVWPs, so please be on the lookout for that. – JLRishe Jan 17 '13 at 07:38
  • Thanks for adding that XSL. Could you also provide the portion I requested in my second comment, from "dvt_1.rowview"? And one more thing - there should be a bunch of `` elements toward the beginning of the XSLT for this DVWP. Could you post those? – JLRishe Jan 17 '13 at 08:20
  • When I mentioned `` I was referring to actual `xsl:param` elements occurring soon after the `xsl:stylesheet` line, not `xsl:with-param`. Perhaps this would be easier if you posted the contents of the whole .aspx up on codebin.org. Would you be able to do that, or is there confidential stuff in it? – JLRishe Jan 17 '13 at 09:08
  • Here: [codebin](http://codebin.org/view/c60826ed) – Akhoy Jan 17 '13 at 09:18
  • From looking at this, ``, it looks like Param1 is bound to a QueryString parameter called 'Year1' and not 'Year'. Could you modify that ` – JLRishe Jan 17 '13 at 09:35
  • After you modified the ` – JLRishe Jan 17 '13 at 10:17
  • Tried that, it doesn't work. – Akhoy Jan 17 '13 at 10:20
  • Ok, last ditch effort and then I think I have to give up until I have the chance to try this myself. Could you locate this row in the list DVWP ``, and modify it to this ``, then try the ` – JLRishe Jan 17 '13 at 10:38
  • Nope, doesn't work. Thanks for taking your time to help me. I think I'mma find another way to do it. – Akhoy Jan 17 '13 at 10:47

2 Answers2

1

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.

Akhoy
  • 502
  • 1
  • 13
  • 24
0

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">
JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • No, this doesn't work. What confuses me is, since I've 2 DVWP's on the page, and since I'm using a different list for the DVWP's, I can't use the filter parameter or the list fields in the other DVWP. Most of the tutorials I followed deal with only 1 DVWP on a page. – Akhoy Jan 17 '13 at 08:45
  • Thanks for all your help. 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. – Akhoy Jan 17 '13 at 13:23
  • Excellent. Thanks for reporting back. So what was the final value of the ` – JLRishe Jan 17 '13 at 13:27
  • The value of the ` – Akhoy Jan 17 '13 at 15:19