?
Solved

Multiple RowFilters on a dataview

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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