Solved

Multiple RowFilters on a dataview

Posted on 2004-08-18
3
815 Views
Last Modified: 2008-02-01
When I add multiple filters on a dataview it seems to ignore the preceding filters and just filters based on one of the criteria. Here is an example:


// Make DataView (for filtering)
                  DataView dv = new DataView();
                  dv.Table = ds.Tables[0];

                  dv.AllowDelete = true;
                  dv.AllowEdit = true;
                  dv.AllowNew = true;

                  // Filter by online
                  if (showOnline.Checked)
                        dv.RowFilter = "isOnline=true";
      
                  // Filter by Gender
                  if (GenderList.SelectedIndex.ToString().Length > 0)
                        dv.RowFilter = "gender="+GenderList.SelectedIndex.ToString();

                  dv.RowStateFilter = DataViewRowState.ModifiedCurrent;

                  // Sort by "Show me first" info
                  if (ShowFirst.SelectedIndex==0) // New People
                        dv.Sort = "LastLoginDate desc";

                  if (ShowFirst.SelectedIndex==1) // Last Logged In
                        dv.Sort = "JoinDate asc";

                  if (ShowFirst.SelectedIndex==2) // Updated
                        dv.Sort = "LastUpdatedDate desc";
                  
                  // Bind to the datalist
                  BrowseResults.DataSource = dv;
                  BrowseResults.DataBind();


This results in just filter for Gender, and not whos online.

Any Ideas?

-- JQ
0
Comment
Question by:JenniQ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
ramesh12 earned 125 total points
ID: 11836489
use and condition

string strFilter;

               if (showOnline.Checked)
                    strFilter = "isOnline=true";

               if (GenderList.SelectedIndex.ToString().Length > 0)
                   if (strFilter.Trim()!="")
                    strFilter = "gender="+GenderList.SelectedIndex.ToString();
                   else
                    strFilter = " AND gender="+GenderList.SelectedIndex.ToString();


........
0
 
LVL 7

Expert Comment

by:ramesh12
ID: 11836492
sorry .

and then apply filter like

 dv.RowFilter =strFilter
0
 
LVL 3

Author Comment

by:JenniQ
ID: 11844053
I think that the RowFilter should work as a collection - just like the SqlParameter class does. That way you can add and remove items in a much less clunky fashion.

It doesn't really explain using multiple filters on the .NET framework sdk either. MS could definitaly allborate on that.

Thanks for your help!

-- JQ

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question