Search This Blog

Thursday, March 3, 2011

How to filter values in a content query web part based on a query string parameter


Additional Filters in a content query web part: 

The below definitions can be viewed by clicking on the help icon beside the Additional Filters section of the Content query web part in edit mode. Most people would not have the patience to click the icon, Hence i have mentioned the details below:
  
You may also enter these tokens as filter values:

  • [PageFieldValue: field name] - uses the value of the specified field of the current page.
  • [PageQueryString: query string parameter name] - uses the value of the specified query string property of the current page URL.
  • If the page field value or query string parameter value is null, the filter will not be included in the query.
  • For date fields, enter an integer value in "Custom Value or Query" to set up a dynamic date range which will be equal to [Today] + [integer value] number of days. 

Tuesday, March 1, 2011

How to show the query string as a title of a list view/Data view web part in SharePoint 2010 using XSLT


Requirement

We needed the title of the xslt list view web part displayed as View "Query string value" documents or View "Query string value" announcements etc

Solution

We considered the following ways to display the title:

  • Using Javascript
  • customizing the XSLT of the list view web part


The second method was followed.

To display the title as the query string in the XSLT list view web part use the following steps:

Click here to learn basics of XSLT.
  1. Edit the page in advanced mode in SharePoint designer (Note: Detach the page from the page layout if you are using a publishing page layout).
  2. Insert the list view web part
    1. Move the cursor over the web part zone in markup or design view. 
    2. From the ribbon's insert tab insert the list using the data view button.
  3. Highlight/Select the list/data view web part in design view.Customize the XSLT of the list view web part from the design tab's Customize XSLT ->Customize entire view option.
  4. With the list/Data view web part highlighted, select the options tab and click on the parameters button.
  5. Create a new parameter with the parameter source as the query string and set the query string variable name to "your query string's variable" name.
  6. Insert the following lines of xslt code, just before the <table> tag to display the query string as a title to the list view web part.
  7. <h2><xsl:value-of select="$ParameterName"/> documents etc</h2>
  8.  Save (and publish) the page.