Monday, 23 April 2007

SharePoint 2007: Query Parameter Filtered Data Views

Using the standard SharePoint OOTB functionality (i.e. using connections from web part to web part) you can filter items in connected web parts but you cannot have only the selected item in the current web part.

Original Web Part (no filtering on selected item)

Data views and SharePoint Designer come to the rescue to filter on the selected item only. You can change the List View Web Part to a Data View Web Part, and then use filters on it to show only the items you need. Using an "old" article "How to use a URL parameter to filter a Data View Web part in FrontPage 2003" and the following article regarding customization of XSLT Data Views you can create this solution.

In SharePoint Designer: Create a new web part page or save the AllItems.aspx (or any other page you want to start from) page as AllItemsEdit.aspx.

Right click on the List Web Part you want to filter and click "Convert to XSLT Data View". This create a Data View web part. To show only the currently selected item you need to change the filterParam ParameterBinding of the DataView from:

ParameterBinding Name="filterParam" Location="Postback;Connection;"


ParameterBinding Name="filterParam" Location="Postback;Connection;QueryString(ID)"

You can put any query parameter instead of ID. I chose to use ID because I will be using the original DispForm link (which already contains the ID param) and thus I won't have to create my own custom URL.

You then need to apply a filter on the Data View. Click on Data View > Filter in SharePoint Designer. Create a new Filter on the column you require, in my case it will be on the ID. In the Value field on the filter you need to use the Drop Down and choose the [Input Paramater].

Save the page, access it with the correct URL, and you should have the filtered item(s) only. You can then add additional web parts and connect them to the filtered data view, or do any other modifications you require.

Connected Web Part showing only selected item:

Beware: This creates Data Sources and other items linked to the current installation which will break if you export to a different installation. (unless you use this solution: Solving the List Guid problem