SharePoint 2010: Data View Web Part And Filter - Part 1

Consider a typical business requirement in which a list of articles or news is filtered based on some default category. Also articles or news need to be filtered based on criteria passed.

Although there are various ways to handle this, let me walk you through a query string based filtering approach using a data view Web part of SharePoint 2010.

Let’s create a new web page named MyDVFilter under Site Pages for our demonstration purpose:

Launch a SharePoint 2010 Designer and locate newly created page under Site Pages.



Open the newly created MyDVFilter page in designer as in the following screenshot:



Add a Data View Web part with ‘Pages’ Data Source. After adding, the data view Web part should display by default on all the available pages. Refer to the following screenshot:



Using Modify View you can Add/Remove Columns from Ribbon options. Verify the column on which the filter needs to be applied is available in view. I would like to apply the filter on WikiCategories, so ensure WikiCategories is added to view.

Let’s define parameters using ribbon Options > Parameters which will filter the data displayed in Data View Web Part. Define new parameter as paramCategory and set Parameter Source as Query String. Set Query String Variable as ‘Category’ which will be actually referred in URL as <URL>?Category=<FilterValue>. Refer to below screenshot for further details:

Select ‘Filter’ icon from ribbon to display Filter Criteria window. Select Wiki Categories as a Field Name and specify Value field as [paramCategory] as shown below,

After saving filter criteria, if there are any default values specified in Data View Parameters, data will be filtered based on default parameter value. If there are any default values, then Data View Web Part will not show any records from the data source. Since we have specified default value for [paramCategory] as ‘Security" Data View Web Part is showing pages of ‘Security’ category only. Refer to below screenshot.

Based on the requiremens, such parameters can be defined in a combination and can be passed as a Query String and page can display required filtered data.

Let’s open a browser window and hit URL with Query String parameter as ‘Category=Security’ to display filtered data. Keep changing value for category and verify results are getting filtered.

This way, just by passing Query String based filter string, we can display required and filtered results using a Data View Web Part.

Up Next
    Ebook Download
    View all
    Learn
    View all