none
Filter a DataFormWebPart with a page/content field RRS feed

  • Question

  • I have a DataFormWebPart within a page layout, and I want to be able to filter this webpart based on a parameter from the Page content. For Example, I have a LookupField in the Page Layout. It is a dropdownlist from a document library in the site, and each page that uses the layout can choose 1 value from the dropdownlist.

    <SharePointWebControls:LookupField FieldName="Related_x0020_Document" runat="server" id="LookupField1">
    </SharePointWebControls:LookupField>


    I would like to be able to filter based on the selected Item. I am able to filter from standard dropdownlist as below, but this is not page content, so no use to me. Strangely, when I add a parameter through the GUI, and choose Control, it gives me a list of all controls including page field and including LookupField1, which would suggest that it is possible, but jus not working.

    <asp:DropDownList runat="server" id="DropDownList1" AutoPostBack="True">
    <asp:ListItem>Risk</asp:ListItem>
    <asp:ListItem>Scope</asp:ListItem>
    <asp:ListItem>Change</asp:ListItem>
    <asp:ListItem>Item</asp:ListItem>
    </asp:DropDownList>

    <ParameterBinding Name="DocLookup" Location="Control(DropDownList1)" DefaultValue=""/>


    Thanks in advance.

    Tomas

    • Edited by Tomas Breen Wednesday, February 4, 2009 4:55 PM
    Wednesday, February 4, 2009 10:09 AM

Answers

  • I have since figured this issue. Thanks for all your help so far :|

    SharePoint lookupfield

    <SharePointWebControls:LookupField FieldName="Related_x0020_Document" runat="server" id="LookupField1">
    </SharePointWebControls:LookupField>

    Binding to a lookup field is different to binding to a text based sharepoint field. A lookupfield, as with a dropdown list has 2 values, the value (ID) and the Text (String). But these are not accessed like a dropdown list. Instead they are returned to the <Parameters> as ; delimited value as seen below.

    The Parameter bindings codebehind.

    <ParameterBindings>
    [Trimmed]
    <ParameterBinding Name="DocLookup" Location="Control(LookupField1,ItemFieldValue)" DefaultValue=""/>
    </ParameterBindings>

    The resulting string value (you can print this to an xslt table with <xsl:value-of select="$DocLookup" />.

    2;#Document Title

    To filter a DataFormWebPart with this value, you first need to tranform it with XSLT. My string is below to find all Documents with a specific title, but you could use it to filter by ID also. The code below filters based on a substring of the string after the #

    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[@Title = substring-after($DocLookup, '#')]"/>    

     

    I hope this helps someone else in the future, as it just took up 2 days of my time.

    R,
    Tomas

    • Marked as answer by Tomas Breen Thursday, February 5, 2009 12:36 PM
    Thursday, February 5, 2009 12:36 PM

All replies

  • I have fond a little bit more information the page/content fields. I have inserted the field in question as a FieldValue.

    <SharePointWebControls:FieldValue runat="server" id="RelatedDocValue" FieldName="Related_x0020__Document"/>

    Then when adding the parameterbinding I have been able to pass in the ID of the content page (not the selected value of the lookup), using the following code. It was lucky that the content page ID (9) had a corresponding item in the lookup table, which allowed me to investigate the source of the value.

    <ParameterBinding Name="DocLookup" Location="Control(RelatedDocValue,ItemId)" DefaultValue=""/>

    I have tried a number of other sources (Value, Text, ItemFieldValue) but to no avail.

    What would be great is be to be able to Debug the page to see object properties, is this possible from SPD?

    Tomas
    Wednesday, February 4, 2009 10:56 AM
  • I have since figured this issue. Thanks for all your help so far :|

    SharePoint lookupfield

    <SharePointWebControls:LookupField FieldName="Related_x0020_Document" runat="server" id="LookupField1">
    </SharePointWebControls:LookupField>

    Binding to a lookup field is different to binding to a text based sharepoint field. A lookupfield, as with a dropdown list has 2 values, the value (ID) and the Text (String). But these are not accessed like a dropdown list. Instead they are returned to the <Parameters> as ; delimited value as seen below.

    The Parameter bindings codebehind.

    <ParameterBindings>
    [Trimmed]
    <ParameterBinding Name="DocLookup" Location="Control(LookupField1,ItemFieldValue)" DefaultValue=""/>
    </ParameterBindings>

    The resulting string value (you can print this to an xslt table with <xsl:value-of select="$DocLookup" />.

    2;#Document Title

    To filter a DataFormWebPart with this value, you first need to tranform it with XSLT. My string is below to find all Documents with a specific title, but you could use it to filter by ID also. The code below filters based on a substring of the string after the #

    <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[@Title = substring-after($DocLookup, '#')]"/>    

     

    I hope this helps someone else in the future, as it just took up 2 days of my time.

    R,
    Tomas

    • Marked as answer by Tomas Breen Thursday, February 5, 2009 12:36 PM
    Thursday, February 5, 2009 12:36 PM
  • Hi Tomas,

    I read your discussion, and I have a similar problem with my layout page which contains a DataFormWebPart, which I need to filter.

    I tried as you mentioned, creating a parameter which is a control, and then from the list select the ID of the control I want to filter on. And it is not working as you mentioned.

    I'm not sure what I have to do in SPDesigner to fix the filtering using the value of the control ID. The control ID is just a SharePointWebControl:TextField. So I need to display only those list items where my Project Name column is equal to the value of my Text field. Keep in mind that my Text field is part of one list, and the Project Name column is part of another list.

    Can you tell me the steps that I need to add to get this to work.
    Monday, October 5, 2009 5:50 PM