Solved

Multiple RowFilters on a dataview

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

12 Experts available now in Live!

Get 1:1 Help Now