test
test

Reputation: 359

Sharepoint DataFormWebPart

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..

Upvotes: 0

Views: 1562

Answers (2)

zincorp
zincorp

Reputation: 3282

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

Upvotes: 1

Zeb
Zeb

Reputation: 506

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.

Upvotes: 0

Related Questions