【问题标题】:How do I search data in from datatable based on user input如何根据用户输入从数据表中搜索数据
【发布时间】:2016-03-01 15:09:08
【问题描述】:

我已经创建了一个数据表:

DataTable dt=new DataTable();
dt.Columns.Add("Country", typeof(string))
dt.Columns.Add("place", typeof(string))
dt.Columns.Add("Price", typeof(string))
dt.Columns.Add("Desc", typeof(string))

我在这个数据表中插入了一些数据:

DataRow dtrow = dt.NewRow();    // Create New Row
dtrow["Country"] = "India";            //Bind Data to Columns
dtrow["place"] = "wizag";
dtrow["Price"] = "7520";
dtrow["Desc"] = "Anywhere";
dt.Rows.Add(dtrow);

dtrow = dt.NewRow();               // Create New Row
dtrow["Country"] = "India";               //Bind Data to Columns
dtrow["place"] = "Goa";
dtrow["price"] = "4500";
dtrow["Desc"] = "Anything";
dt.Rows.Add(dtrow);

我已将此数据表与我的网格视图绑定。我还在 mmy aspx 页面中添加了一个文本框和一个搜索按钮。我的要求是我想根据用户输入搜索数据,例如 4500 或 wizag,如果国家名称相同,我想在一行中显示它

我该怎么做?

【问题讨论】:

  • 尝试mva.microsoft.com/en-us/training-courses/… 或在asp.net 上获得一本好书
  • 如果您向我们展示您的尝试,并描述您遇到的问题,您更有可能得到有用的答案。
  • 先生,我只想搜索数据表作为用户提供的输入,它可能是任何国家名称或价格或地点 .................... …………
  • @abhinaykumar 我的方法是否帮助您解决了问题?

标签: c# asp.net .net datatable


【解决方案1】:

在这种情况下我会使用DataView

DataView dv = new DataView(dt);
dv.RowFilter = "price = 4500 AND Country = 'India'"; 
GridView.DataSource = dv.ToTable();
GridView.DataBind();

【讨论】:

    猜你喜欢
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-02
    相关资源
    最近更新 更多