How to filter multiple rows in dataview
Question
I need to filter multiple rows in dataview. Here I used rowfilter. But, I want to filter multiple rows. Which command can be used? My code is:
foreach (string s1 in list)
{
if (s1 != string.Empty)
{
dvData.RowFilter = "(code like '" + searchText + "*') AND (code <> '" + s1 + "')";
}
}
The problem is, it takes only one value and it is overwritten during the loop.
Solution
If you want to add all codes for code
field in RowFilter
then you can try this:
StringBuilder sb = new StringBuilder();
foreach(string s in list){
if (s != string.Empty)
sb.Append(string.Format(" AND (code <> '{0}')", s));
}
string rowFilter = string.Format("(code like '{0}*')", searchText) + sb.ToString();
dvData.RowFilter = rowFilter;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow