Solved

Multiple RowFilters on a dataview

Posted on 2004-08-18
3
809 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now