FrontPoint

Using Microsoft FrontPage to do amazing things with SharePoint Products and Technologies

Using a form to filter a data view web part - or NOT

This is a modified post.  My original code sample was more complicated than it needed to be.  This one is WAY simpler.

I was just thinking that it should be a lot easier to use a Form Web Part and be able to either filter a data view based on that Form's contents, or to pass in an “ALL” value.  Basically, when you enable the Filtering toolbar for the Data View, this is what you get, but in my scenario, I wanted to be able to go cross-page with my filter.

My wife had a baby 2 weeks ago, so I've been OOF for a bit, but this morning I sat down and decided I needed to enable this for my baby's blog...

Here it is.  For this example, I just use the Announcements list default views because wss sites usually get this list by default.

  1. On a new page insert a few of the Announcements list
  2. Insert a Form Web Part
  3. Change the input type of the Form to be a drop-down field and add some values:
    1. All
    2. 1
    3. 2
  4. Place the cursor into the Data View you created in Step 1 and click on Table..Select > Row
  5. Click on Data..Conditional Formatting
  6. Click on Create
  7. Click on “Show content...“
  8. Field Name == ID
  9. Comparison == Equals
  10. Value == [Input Paramter]
  11. Click OK
  12. Right click the Form Web Part > Web Part Connections
  13. Provide Data Values to...
  14. Web Part on this page...
  15. Modify view using Parameters from...
  16. D1 == Input Parameter
  17. Finish the wizard
  18. Now switch to code view
  19. Add an OR so that we test for the FilterParameter saying 'All'.

currently, the dvt_1.body template looks like this:

         <xsl:template name="dvt_1.body">
             <xsl:param name="Rows"/>
             <xsl:param name="FirstRow"/>
             <xsl:param name="LastRow"/>
             <xsl:for-each select="$Rows">
                 <xsl:variable name="KeepItemsTogether" select="false()"/>
                 <xsl:variable name="HideGroupDetail" select="false()"/>
                 <xsl:variable name="GroupStyle" select="'auto'"/>
                 <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $KeepItemsTogether">
                     <xsl:if test="not($HideGroupDetail)" ddwrt:cf_ignore="1">
                         <xsl:if test="@ID = $filterParam">
                             <tr style="display:{$GroupStyle}">
                                 <td class="ms-vb"><xsl:value-of select="@Title"/></td>
                                 <td class="ms-vb"><xsl:value-of select="@Editor"/></td>
                                 <td class="ms-vb"><xsl:value-of select="ddwrt:FormatDate(string(@Modified), 1033, 5)"/></td>
                             </tr>
                         </xsl:if>
                     </xsl:if>
                 </xsl:if>
             </xsl:for-each>
         </xsl:template>

You need to add the code in bright red:

         <xsl:template name="dvt_1.body">
             <xsl:param name="Rows"/>
             <xsl:param name="FirstRow"/>
             <xsl:param name="LastRow"/>
             <xsl:for-each select="$Rows">
                 <xsl:variable name="KeepItemsTogether" select="false()"/>
                 <xsl:variable name="HideGroupDetail" select="false()"/>
                 <xsl:variable name="GroupStyle" select="'auto'"/>
                 <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $KeepItemsTogether">
                     <xsl:if test="not($HideGroupDetail)" ddwrt:cf_ignore="1">
                         <xsl:if test="@ID = $filterParam or $filterParam = 'All'">
                             <tr style="display:{$GroupStyle}">
                                 <td class="ms-vb"><xsl:value-of select="@Title"/></td>
                                 <td class="ms-vb"><xsl:value-of select="@Editor"/></td>
                                 <td class="ms-vb"><xsl:value-of select="ddwrt:FormatDate(string(@Modified), 1033, 5)"/></td>
                             </tr>
                         </xsl:if>
                     </xsl:if>
                 </xsl:if>
             </xsl:for-each>
         </xsl:template>

20. Save the page and check it out in the browser.

Good luck!
-John

Published Thursday, June 10, 2004 1:14 PM by frontpoint

Comments

 

SharePoint, SharePoint and stuff said:

Ok, es tut sich mal wieder viel im SharePoint-Universum.
June 11, 2004 6:35 AM
 

SharePoint, SharePoint and stuff said:

Ok, es tut sich mal wieder viel im SharePoint-Universum.
June 11, 2004 6:38 AM
 

Elizabeth Grigg said:

Congrats on the baby! Ours was June 3, was yours the same?
June 18, 2004 4:19 PM
 

John Jansen said:

May 27th, actually. Now I need a nap.
June 18, 2004 4:45 PM
 

Kathleen Anderson said:

Congratulations, John - I hope everyone's doing well!
June 29, 2004 6:52 PM
 

Colin Walker said:

Only just come back across this post after the update.

Congrats on the baby :)

Thanks for this post - it's inspired me to have a play on my blog :)
July 16, 2004 1:11 AM
 

dataview does not return any data when no arguments passed to filt | keyongtech said:

January 22, 2009 2:58 AM
 

FrontPoint Using a form to filter a data view web part or NOT | Paid Surveys said:

May 29, 2009 7:44 PM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker