2016-03-01 29 views
-1

我已經創建了一個數據表用戶輸入從數據表中檢索數據:如何基於

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,如果國家名稱相同,我想將它顯示在一行中

我該怎麼做?

+0

嘗試使用DataView https://mva.microsoft.com/en-us/training-courses/introduction-to-asp-net-mvc-8322或獲得關於asp.net的一本不錯的書 – BugFinder

+0

如果你向我們展示你的嘗試,並描述你遇到的問題,你很可能會得到一個有用的答案。 – Rook

+0

先生只有我想搜索datatable作爲輸入提供的用戶可能是任何國家的名稱或價格或地點.......................... ..... –

回答

0

我想在這種情況下

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