Binding query string parameters

Sunbox data view has the default mechanism of binding current query string parameters.

There are two scenario avaliable:
  1. You need to use query string parameter value in the Query option of data source (you need to query data list item with specified ID or other parameter from query string).
  2. You need to use query string parameter value in your XSL template;

Query string parameters in the Query

Query string parameters values can be used in Query option of each data source. For this purposes you should use:

{querystring[name]}


For example, if you want to query item with ID, specified by "id" query string parameter you should set Query option of the data source to:

<Query>
  <Where>
    <Eq>
      <FieldRef Name="ID" ></FieldRef>
      <Value Type="Int">{querystring[id]}</Value>
    </Eq>
  </Where>
</Query>


After that, if you goto the adress like: page.aspx?id=10 - data source return only 1 list item with ID = 10.

Query string parameters in the XSL template

Query string parameters values can be used in XSL template. For this purposes Sunbox data view creates a special node element in the source XML tree named "bindings". This element contains child element "QueryStrings", which contains childs for each current query string parameter, example:

<response>
  <__bindings>
    <QueryStrings>
      <pageview>Shared</pageview>
      <initialtabid>Ribbon.WebPartPage</initialtabid>
      <visibilitycontext>WSSWebPartPage</visibilitycontext>
      <id>10</id>
    </QueryStrings>
    <Parameters/>
  </__bindings>
  .....
</response>


Query string nodes of parameter allways low capatalized. For using them in your XSL template:

<xsl:value-of select="/response/__bindings/QueryStrings/id" />

Last edited Mar 14, 2012 at 6:27 AM by Bukharin, version 5

Comments

No comments yet.