Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple RowFilters on a dataview

Posted on 2004-08-18
3
Medium Priority
?
818 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 500 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

596 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