How to filter data in dataview
asp.net, c#
Solution
DataView view = new DataView();
view.Table = DataSet1.Tables["Suppliers"];
view.RowFilter = "City = 'Berlin'";
view.RowStateFilter = DataViewRowState.ModifiedCurrent;
view.Sort = "CompanyName DESC";
// Simple-bind to a TextBox control
Text1.DataBindings.Add("Text", view, "CompanyName");
Ref: http://www.csharp-examples.net/dataview-rowfilter/
http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx
Problem
I want to filter data on the textchange event on listview so I use dataview to filter data. Issue in the below code is, I use dataview inside for each so that it checks only one condition that is last value only it takes, I want to check value in s1 with dataview and remaining value should bind with listview. eg: if I type an in textbox it should list all the item values starting with an value like anandha kumar,anna ect. suppose I keep the value anandha kumar and anna in array s1. I should list all other values expect the array values like antony ect... in listview. ``` protected void TextBox1_TextChanged(object sender, EventArgs e) { dvProducts = (DataView)Session["ListViewItems"]; string serachText = EscapeLikeValue(TextBox1.Text); string lvValues = hdRetailCustomerGroup.Value; string trim = lvValues.Replace(" ", ""); trim = trim.Replace("\r", ""); trim = trim.Replace("\n", ""); trim = trim.Replace("\t", ""); string str = trim; string[] list = str.Split('|'); foreach (string s1 in list) { if (s1 != string.Empty) { dvProducts.RowFilter = "(CODE like '" + serachText + "*') AND (CODE <> '" + s1 + "')"; Session["ListViewItems"] = dvProducts; } } ListView1.DataSource = dvProducts; ListView1.DataBind(); } ```