All well and good until we needed to filter a dataview on fields that are not part of the dropdown. In database terms we neded to do an inline view so that the results of one query were the parameters of another. We were looking at Webpart connections as a possibility but documentation is not exactly abundant. I did find a YouTube video that explained how Webpart connections work and allowed me to work out the rest.
The process is:
- Open the .aspx page in Sharepoint Designer (this uses Sharepoint Designer 2007, other versions may differ)
- Create a webpart dataview to do the 'inline view' sub-query, this only has the fields need for parameters for the filters on the main webpart dataview. This will be referred to as the providor webpart and the main webpart dataview that displays the actual data will be referred to as the consumer webpart.
- Set any filters required, the result of this should be to return only one row of data for each value..
- Make sure that both webpart dataviews have a meaningful name.
- On the providor webpart open the "Common Dataview Tasks" menu and select Webpart Connections.
- A dialogue should open giving the name of the Providor Webpart as Source Webpart and 'Send Row of Data To' as the Source action. The source action can be selected via a dropdown box in the lower part of the dialogue, leave it as 'Send Row of Data To' or change it to that if it has not defaulted to that. Click Next.
- The next step give you the option of connecting to a webpart on the same page or another, select to use a webpart on the same page and click Next.
- You can now select the consumer web part in the Target WebPart drop down box. In the Target Action select 'Get Parameters From'. Click Next
- The next step will show a two column table in the lower part of the dialogue, the left column should be named "Columns in [Name of Providor WebPart]" and the right column should be named "Inputs to [Name of Consumer WebPart]". In the right column there will be listed any existing parameters on the Comsumer WebPart (there may be just the default one of ListID) and at the bottom <create new parameter>. Select <create new parameter>, the normal prameter creation box should appear.
- For each parameter you need create a parameter with a short but meaningful name. The 'Parameter Source' drop down should be greyed out and the 'Default Value' should be blank, leave them as they are. Once you have created your parameters click OK to return to the Webpart Connection dialogue.
- Your parameters should now be listed in the right column. in the left column cell against each one click to select the cell, this will cause a drop down to appear. Open the dropdown and select the field from the Providor WebPart that you want to populate the parameter. Repeat for each parameter then click Next twice then finish to close out the dialogue.
- Now go to the Consumer webpart and open the Common DataView Tasks menu. Select Filter.
- The normal filter dialogue will open and you can create the filters as normal but instead of creating the parameters you should select the parameters that you have just created. Click OK to save the filters.
- You probably won't want to display the Providor webpart so select the table it is embedded in and open the Table Properties. Set width and height to zero and click OK. Finally, select the webpart and open WebPart Properties, open the Layout area and select hidden then OK. The webpart will still be visible in Designer but won't be when the page is viewed in a browser.