如何在数据视图中过滤数据 [英] How to filter data in dataview

查看:160
本文介绍了如何在数据视图中过滤数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想过滤listview上textchange事件的数据,所以我使用dataview过滤数据.下面的代码中的问题是,我在每个内部使用dataview,以便它仅检查一个条件,该条件仅是最后一个值,我想使用dataview检查 s1 中的值,并且剩余值应与列表视图.

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.

例如:如果我在文本框中输入 an ,则应列出所有项目值,并以anandha kumar,anna ect之类的值开头.假设我将值anandha kumar和anna保留在数组s1中.我应该列出所有其他期望值,例如listview中的antony ect....

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();

        }

推荐答案

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");

参考: http://www.csharp-examples.net/dataview-rowfilter/

http://msdn.microsoft.com/en-us/library/system.data.dataview.rowfilter.aspx

这篇关于如何在数据视图中过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆