Filtering Data Views With Query String
A few days ago I needed to filter web part with values from a web part that is located in another page. Usually I would have done it with Query String (URL) Filter web part. Unfortunately, my client didn’t have enterprise edition and I had to think of another way to implement this. The answer was (of course) Data view! lets see how it can be done.
Create 2 pages - the first will display the web part with the values, the second will be filter by these values.
Go to your first page and create data view with the values to filter by (in this example documents types).
Now, make the values clickable: Click on the name of the field and choose Hyperlink in Format as… field.
In the address filed chose the destination page (the second page you created – number 1 in the following picture) and add the parameters in this structure: ParmName={@Filed} in this example DocType={@Title} (Number 2 in the following example).
For every parameter you would like to pass in the URL you will need this structure; in order to add more parameters use &. For example: DocType={@Title}&ID={@ID}. Click ok.
- The display name was change – use only {@Title} (or any other filed you need) (Number 3 in the above example).
- The value are now Hyperlinks (next picture).
Reattach the page, check it in and close it.
Detach the second page from its layout and insert you data view. This data view should be the one that will be filter according to the values in the first page.
Click on the small arrow next to the data view and chose filter. Under the field name chose the field that will be filter (in my example – document type); Under value chose Create new parameter…
Data view parameters window will appear. Under Parameters source chose Query String, under Query String Variable enter the parameter you used in the first page as hyperlink (as shown in the following picture). In my example: DocType. You can also add default value. Click OK and then Ok.
You can see that now, there are no items in the web part. For your connivance you can check Show with sample data checkbox (in the Common data view tasks menu).
Reattach the page, check it in and close it.
Now, let’s go to the first page we created. Click on one of the filter values and see the result…
(I clicked on Detailed Design and here is the result…)
In this example I chose to display “document type” in the data view in second page (in addition to the first page). When you’re using data view it is not necessary; But when you are using the browser web parts you have to display these fields in order to filter the web parts.
I find this way much easier to work with (rather than URL Filter web part) because when your working with the filter web part – every time you will edit the page in the SPD the connection will be remove automatically (unless you’re working in code mode all the time).
Hope this post was helpful.
Inbar.