How to filter data in dataview

前端 未结 2 1565
闹比i
闹比i 2021-01-04 14:04

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 onl

相关标签:
2条回答
  • 2021-01-04 14:38

    Eg:

    Datatable newTable =  new DataTable();
    
                foreach(string s1 in list)
                {
                    if (s1 != string.Empty) {
                        dvProducts.RowFilter = "(CODE like '" + serachText + "*') AND (CODE <> '" + s1 + "')";
                        foreach(DataRow dr in dvProducts.ToTable().Rows)
                        {
                           newTable.ImportRow(dr);
                        }
                    }
                }
    ListView1.DataSource = newTable;
    ListView1.DataBind();
    
    0 讨论(0)
  • 2021-01-04 14:45
    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

    0 讨论(0)
提交回复
热议问题