C# 如何根据用户输入从datatable中搜索数据
我创建了一个数据表:C# 如何根据用户输入从datatable中搜索数据,c#,asp.net,.net,datatable,C#,Asp.net,.net,Datatable,我创建了一个数据表: 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 R
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);
我在这个数据表中插入了一些数据:
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,如果国家名称相同,我希望将其显示在一行中
我该怎么做 在这种情况下,我将使用
DataView
DataView dv = new DataView(dt);
dv.RowFilter = "price = 4500 AND Country = 'India'";
GridView.DataSource = dv.ToTable();
GridView.DataBind();
尝试或在asp.NET上获得一本好书如果您向我们展示您的尝试,并描述您遇到的问题,您更有可能得到有用的答案。先生,我只想搜索数据表作为用户提供的输入,它可能是任何国家的名称、价格或地点………..@abhinaykumar我的方法是否帮助您解决了问题?