0

I need to filter my list based on selected dropdown value. I've created a DVWP for that and converted it into a dropdown. Now I'm following this post to fire events when dropdown value is selected but I just do not know where to change the code. I'm filtering the list based on years. I have an year list which stores year values and filters it accordingly when the dropdown is selected. I've modified it like this:

<xsl:otherwise>
  <select name="ID" size="1" onchange="document.location.href='pageName.aspx?year=' + this.options[selectedIndex.value])">
    <option selected="true" value="0">Choose One...</option>
    <xsl:call-template name="dvt_1.body">
      <xsl:with-param name="Rows" select="$Rows" />
    </xsl:call-template>
  </select>

I've no idea of xslt and this isn't firing any event when i change the dropdown value. Please help me with this.

Update: The HTML I get:

<td valign="top">
  <div WebPartID="9e0da2fd-21ea-417f-863d-6551d16e72a1" HasPers="false" id="WebPartWPQ3" width="100%" class="noindex" allowDelete="false" style="" >
    <select name="ID" size="1" onchange="document.location.href='http://pageName.aspx?year=' + this.options[selectedIndex].value" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
      <option selected="" value="0">Choose One...</option>
      <option>2009</option>
      <option>2010</option>
      <option>2011</option>
      <option>2012</option>
      <option>2013</option>
    </select>
  </div>
</td>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Akhoy
  • 502
  • 1
  • 13
  • 24

1 Answers1

0

I'm somewhat doubtful that this is an XSLT issue. The script for the onchange handler in that tutorial seems to boil down to:

document.location.href='pageName.aspx?year=' + this.options[selectedIndex].value

Note that .value is outside the []. Could you give that a try? Is your browser reporting any JavaScript errors when you change the dropdown selection?

Now, according to this tutorial, you can filter a list by specifying query parameters named FilterField1, FilterValue1, etc, so could you try something like this:

document.location.href='pageName.aspx?FilterField1=ColumnName&amp;FilterValue1=' 
 + this.options[selectedIndex].value + '&amp;year=' + this.options[selectedIndex].value

Here you would replace "ColumnName" with the actual name of the column, as indicated in that tutorial. Could you try something like that?

JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • Thanks for replying! The page is getting post back now but no grouping's happening. And, is giving the page name sufficient or do I have to give the server name like what I have done? No, the browser isn't giving any error messages. – Akhoy Jan 16 '13 at 14:11
  • Ok, the next thing to verify is that your browser address bar is showing the expected URL, and that you have `year=_expected value_` at the end of the URL. Have you gone through the instructions in the blog post to add `year` as a Query String Parameter for the DVWP? Have you modified the XSL to make use of that parameter? – JLRishe Jan 16 '13 at 14:19
  • Yes, the browser address bar does display the proper url. And I have added year as a parameter but I don't know how to make use of that year parameter. – Akhoy Jan 16 '13 at 14:21
  • Ok, just found out that I have to pass the parameter explicitly instead of manually typing year in the `document.location.href`. Doing it with `onchange=""` isn't working, so I guess I'll have to make a JS function. Can you please tell me where to write a javascript function in the xslt page. Can I write it anywhere or inside a placeholder? – Akhoy Jan 16 '13 at 14:35
  • Added a suggestion to my answer. – JLRishe Jan 16 '13 at 14:37
  • I'm not quite sure what you have in mind when you say "pass the parameter" explicitly. If you do need to add JavaScript functions, can presumably add the ` – JLRishe Jan 16 '13 at 14:40
  • When I add this line to `onchange=""`, it gives me an error and doesn't render the DVWP. I guess only single quotes work. When I change you `""` to `''`, it works. – Akhoy Jan 16 '13 at 14:52
  • Yes, my mistake. `onchange=""` starts and ends with double quotes so it can't contain double quotes. So are you saying that the filtering works with the above modification? – JLRishe Jan 16 '13 at 14:57
  • This code works perfectly though. Thanks a lot. Could you tell me how to use the Query string parameter as well? Thanks. – Akhoy Jan 16 '13 at 14:58
  • Sorry. My bad. I thought it worked but tried using different fields in the browser address bar. It doesn't work. – Akhoy Jan 16 '13 at 15:05
  • From what I understand (I've never used a Query String parameter in a DVWP), the parameter is passed into the XSLT as a parameter, and then you can access it within your XSLT as $[parameterName], as in ``. Apparently there is also a way to configure a DVWP's filtering and use the parameter there as well: [MSDN thread](http://social.msdn.microsoft.com/Forums/nl-NL/sharepointcustomizationprevious/thread/97c92ece-bb57-4aa0-82d4-1f1d16d4cdcc). – JLRishe Jan 16 '13 at 15:05
  • So it works for some fields and not for others? If so, are you sure you're using their actual column names and not their display names? – JLRishe Jan 16 '13 at 15:09
  • From what I tried, this trick only works for lists and not views. Every view I tried this with, it didn't work. – Akhoy Jan 16 '13 at 15:49
  • By "views" do you mean supplementary views associated with a SharePoint list, or data views? – JLRishe Jan 16 '13 at 15:55
  • By "views", I mean data views. – Akhoy Jan 16 '13 at 15:59
  • The link I provided 4 comments up that says "MSDN thread" appears to have information on how to use a QueryString parameter to filter a data view. I believe the QueryString parameter would need to be added to that data view as well, and then there's a dialog where you can indicate a filter on that parameter. Have you tried that? – JLRishe Jan 16 '13 at 16:03
  • Yeah, tried it. Actually, no matter what filtering I do in the URL(even from the browser address bar), it just doesn't filter the view! – Akhoy Jan 16 '13 at 16:22
  • Forgot to mention a very important point. I'm displaying the list data in a DVWP AND doing the filtering used a ddl DVWP as well. So, it's 2 different DVWPs. Would that make any difference? – Akhoy Jan 16 '13 at 16:28
  • Yes, so what I'm saying is that you would add the QueryString parameter _at least_ to the list DVWP, and also to the dropdown DVWP if you need it there. Then you would set up a filter on the **list** DVWP to filter based on that parameter. I haven't tried this yet myself so I probably can't suggest much more than that. – JLRishe Jan 16 '13 at 16:31
  • Sorry for replying so late. Yeah, I have done that now. In the ddl DVWP, I've added `Param1` with `QueryString:Year` and in the list DVWP, I've added the same and I'm filtering based on `year=[Param1]`. Note: added a new year col to make it easier. Now, the URL gives http://server.aspx?year=2012 but doesn't filter. How do I use the year in the querystring to filter? – Akhoy Jan 17 '13 at 05:34
  • I think this discussion is getting very drawn out and I think it would make sense to separate it from the original issue, which was about sending query parameters from the dropdown. Could you open a separate question about the filtering issue? – JLRishe Jan 17 '13 at 06:03