We help IT Professionals succeed at work.

Dataview filter not showing "ALL" data from dropdown menu

3,639 Views
Last Modified: 2013-11-18
I have built a page on our Sharepoint 2007 website that uses a dataview to display data from a very basic SQL 2005 database. I have created the dataview and added 2 Dropdown menus to filter the information. no auto post back because I have also placed a submit button that uses the post back URL. This way they can choose all the data from the dropdowns and then display the filtered results on the dataview part of the page. This all works fine.

However, I want to be able to choose "Display all data" from the dropdown to see everything. I have tried to use the XSLT filter to do this but cant get it to work. below are the details.

Drop down box 1: called dropdownbox1 uses "SELECT DISTINCT [lnumber] FROM [list] WHERE ([lnumber] IS NOT NULL) ORDER BY [lnumber]"

Drop down box 2: called dropdownbox2 uses "SELECT DISTINCT [timezone] FROM [list]"

The data view has two filters associated with it
1) lnumber = Param1
            Parameter Source: Control
            Control ID: dropdownlist1
            Default Value: All
2)TimeZone = Param2
            Parameter Source: Control
            Control ID: dropdownlist1
            Default Value: All

Add XSLT filtering is checked and the following code is used...
[@lnumber = $Param1 or $Param1 = '(All)' and @timezone= $Param2 or $Param2 = '(All)']
I have AppendDataBoundItems set to True and have manually added two items to the drop downs...
Select --- Enabled: True - Selected: True - Text: Select - Value: Select
All --- Enabled: True -  Selected: False - Text: All - Value: All

When the XSLT filter is enabled and used with the above code, the dropdowns have no effect. It always say there is not data to show.

Hope I have given enough detail, if not let me know and thanks for the help.
Chris
     

Comment
Watch Question

Author

Commented:
The default Value for Param1 is Select, not All. Sorry


1) lnumber = Param1
   Parameter Source: Control
   Control ID: dropdownlist1
   Default Value: Select
2)TimeZone = Param2
   Parameter Source: Control
   Control ID: dropdownlist1
   Default Value: All

Commented:
never worked with sharepoint, not sure if it works or not

try

[(@lnumber = $Param1 or $Param1 = '(All)') and (@timezone= $Param2 or $Param2 = '(All)')]

Commented:
sorry try this

never worked with sharepoint, not sure if it works or not

try

[(@lnumber = $Param1 or $Param1 = '(Select)') and (@timezone= $Param2 or $Param2 = '(All)')]

Author

Commented:
I opened the dataview and removed all the filters except for the XSLT and pasted in your code above. However when I go to the page and choose "All" on both dropdowns, click the submit button, the page refreshes and still tells me there is no data to display.

If I remove the XSLT and all filters than all the data is displayed, but of course I cant filter at that point.

Thanks.

Author

Commented:
Anyone still looking at this?

Author

Commented:
Last try...any suggestions on this?

Commented:
If this is purely XSLT filtering, which it seems to be based on what you have provided thus far then you might want to try this based upon a good thread related to your topic at: http://blogs.msdn.com/sharepointdesigner/archive/2007/03/05/asp-net-controls-filter-the-data-view.aspx

(code snippet posted from extract from above url)

If you used Sharepoint Designer and added parameters via the UI for the dataview webpart there is a bug that exhibits will often exhibit itself if you make changes to the parameter list.  When you do so the UI will erase the SelectParameters section in your DataFormWebPart.  If you are using any parameters then you will want to ensure that you manually code these back in.  Here is an example:

<SharePoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="<View></View>" UseInternalName="True" ID="IT_x0020_Work_x0020_Schedule_x0020_Calendar1">
<SelectParameters>
<WebPartPages:DataFormParameter ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="7E939CC2-D987-4D60-8BCD-1D445830B998" Name="ListID">
</WebPartPages:DataFormParameter>
</SelectParameters>
 
Add multiple WebPartPages:DataFormParameter tags for each parameter you are passing to your datasource.  This may not apply if you aren't using parameters to filter your datasource, I only mention it here because it is an issue that exhibits itself with the same message that you mentioned you are getting without any records displayed.
1. Click in the Data View
2. Click on Data View > Filter
3. Delete the filter that is set there
4. Click OK
5. Switch to Code View
6. Find the line that says: <xsl:template name="dvt_1.body">
7. Add a line of code to that template just before the call template:
 
<xsl:if test="@CategoryName = $Param1 or $Param1 = '(All)'">
 
Your code will look like this:
 
<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:if test="@CategoryName = $Param1 or $Param1 = "'(All)'">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:if>
</xsl:for-each>
</xsl:template>

Open in new window

Author

Commented:
When I put in this code it tells me required white space in missing...here is the part of the code you described above...if I need to post more let me know
<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="dvt_KeepItemsTogether" select="false()" />
			<xsl:variable name="dvt_HideGroupDetail" select="false()" />
			<xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
				<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
					<xsl:call-template name="dvt_1.rowview" />
				</xsl:if>
			</xsl:if>
		</xsl:for-each>

Open in new window

Author

Commented:
Sorry I meant to post what I did from your directions as well...here is what the code looks like after I followed your directions...
Stupid question...but what should I put in @CategoryName? I thought it was the field that I was keying off of but whatever I put in there it comes up with the "Error: Required white space was missing"

Thanks for your help.
<xsl:template name="dvt_1.body">
		<xsl:param name="Rows"/>
		<xsl:for-each select="$Rows">
		<xsl:if test="@CategoryName = $Param1 or $Param1 = "'(All)'">
			<xsl:call-template name="dvt_1.rowview"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
		<xsl:param name="FirstRow" />
		<xsl:param name="LastRow" />
		<xsl:for-each select="$Rows">
			<xsl:variable name="dvt_KeepItemsTogether" select="false()" />
			<xsl:variable name="dvt_HideGroupDetail" select="false()" />
			<xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
				<xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
					<xsl:call-template name="dvt_1.rowview" />
				</xsl:if>
			</xsl:if>
		</xsl:for-each>

Open in new window

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.