Pregunta

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.

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top