views:

368

answers:

2

Hi,

Within my DataFormWebPart I have a 'DataSourcesString' property which references and queries a list.

Depending on what page the DataFormWebPart is displayed on I need to be able to configure the query (parameterise the string 'Dispute Resolution' in the code below) within the 'DataSourcesString'.

Does anyone know if there a way to paramterise this by modifying the web part through either the XSL Editor or Paramter Editor?

The web part code snippet relating to the 'DataSourcesString' is below

  <property name="DataSourcesString" type="string">&lt;%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;&lt;sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&amp;lt;View&amp;gt;&amp;lt;Query&amp;gt;&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name=&amp;quot;ID&amp;quot;/&amp;gt;&amp;lt;/OrderBy&amp;gt;&amp;lt;Where&amp;gt;&amp;lt;Eq&amp;gt;&amp;lt;FieldRef Name=&amp;quot;Primary&amp;quot;/&amp;gt;&amp;lt;Value Type=&amp;quot;Text&amp;quot;&amp;gt;Dispute Resolution&amp;lt;/Value&amp;gt;&amp;lt;/Eq&amp;gt;&amp;lt;/Where&amp;gt;&amp;lt;/Query&amp;gt;&amp;lt;/View&amp;gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1"&gt;

Thanks! I appreciate this may not be so clear without screenshots..

A: 

The only way I found of manipulating parameters at run time was from C# code behind.

Here are the steps required:

  1. Dump your DataFormWebPart code into an ascx control. (or a custom webpart if you wish).
  2. In the code behind of the control, reference your DataFormWebPart via it's ID just like you would to any other user control such as a text box.
  3. Use the DataFormWebPart object to fiddle with its Data Source (if required) and its queries. You can get a handle on all of its parameters.
Zeb
+1  A: 

You can do this using a QueryString parameter on the DataForm. I'm assuming you're only able to export the webpart. So, export the webpart and save the .webpart to your desktop. Open it and modify it like so:

In your DataSourcesString remove the where clause entirely:

<property name="DataSourcesString" type="string">&lt;%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %&gt;&lt;sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&amp;lt;View&amp;gt;&amp;lt;Query&amp;gt;&amp;lt;OrderBy&amp;gt;&amp;lt;FieldRef Name=&amp;quot;ID&amp;quot;/&amp;gt;&amp;lt;/OrderBy&amp;gt;&amp;lt;/Query&amp;gt;&amp;lt;/View&amp;gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1"&gt;

In the <property name="ParameterBindings" type="string"> node, add:

&lt;ParameterBinding Name="MyVariable" Location="QueryString(MyVar)"/&gt;

In the XSL for the webpart itself, find &lt;xsl:param name="dvt_partguid" /&gt; and just below it add:

&lt;xsl:param name="MyVar" /&gt;

Finally, find select="/dsQueryResponse/Rows/Row and modify it to be:

select="/dsQueryResponse/Rows/Row[@Primary='$MyVar']

Save the webpart, upload it back, and you should now be able to filter it by adding MyVar=Whatever to your querystring

zincorp
Thanks, can you tell me where exactly can I edit the querystring for the web part?
nav
I figured out I had the make the connection to the querystring on the web part. But can't figure out what to enter in the parameters editor for MyVar. I tried this but didnt get the right result ... ParameterBinding Name="MyVariable" Location="QueryString(lt;Where><Eq><FieldRef Name="Primary"/><Value Type="Text">Dispute Resolution</Value></Eq></Where>)"/>
nav
It should look exactly as I pasted it: <ParameterBinding Name="MyVariable" Location="QueryString(MyVar)"/> - This tells it to grab the QueryString parameter named "MyVar"
zincorp
thanks, but what i was trying to ask was where in the web part's configuration should the querystring be edited?
nav