Using Querystrings in a SharePoint DataFormWebPart

Throughout my adventure of SharePoint development, there have been a few times when I needed to use a querystring variable in a DataForm WebPart that was not a part of the data being queried. An example is to use a DataForm Web Part as a means to create a link to another page – with the link containing querystring variables from the datasource used by the DataForm Web Part. If you are unfamiliar with using data fields in the XSL stylesheet in SharePoint page, you can output field values of the current record through {@fieldname}, such as {@ID} will be replaced with the ID value for that record.

In one situation I had two querystring variables that were used on one page, with neither querystring variable being contained within the dataset of the other querystring. Example, account_ID and ad_ID, two indirectly related querystrings that were only linkable through a traditional multi-level table join, such as Accounts > Events > Ads. So how would I output the unassociated querystring in the DataForm of the associated querystring – in other words, how do I use {@field} to output ad_ID when I am working in the Accounts table with querystring account_ID. Well, at first, I had a hard time figuring this out. Depending on the day, I am either thinking too big or too small; either way, the solution seems to always be in the middle.

{$parameter}

As one would add a parameter to filter the datasource results, add a parameter sorely for the purpose of outputting the value in the XSL stylesheet. Simple! Now you can output the querystring value in your XSL by using {$parameter_name}.

If you are unfamiliar with creating parameters, click on the little arrow to the right on the DataForm WebPart and choose “Parameters…”. The name you provide for the parameter will be the same name you use in the {$p..} variable.

About aaron

IT is not just a job but also a passion. Everything I have accomplished, both personally and professionally, has been generally entertaining, bordering on fun. Some of my projects, such as working with SharePoint Services workflow actions in Visual Studio or building a custom iSCSI SAN using the OpenSolaris, ZFS and COMSTAR, has been quite rewarding. You may think nerd...I think developing a new trend!