2010-10-05 73 views
2

我正在從sql數據庫中檢索數據。我想分割記錄並將其綁定到三個不同的網格中。在應用分頁之前,一切正常。我得到數據源不支持服務器端數據分頁。錯誤在asp.net中使用linq的Gridview分頁

代碼:

DataTable StoreDisplayTypeList = storeDisplayBL.GetStoreDisplayDetails(); 

     var specialBook = from myRow in StoreDisplayTypeList.AsEnumerable() where (string)myRow["StoreDisplayType"] == "Special Book" select myRow; 
     var newRelease = from myRow in StoreDisplayTypeList.AsEnumerable() where (string)myRow["StoreDisplayType"] == "New Release" select myRow; 
     var Seller = from myRow in StoreDisplayTypeList.AsEnumerable() where (string)myRow["StoreDisplayType"] == "Best Seller" select myRow; 
     var featuredEdition = from myRow in StoreDisplayTypeList.AsEnumerable() where (string)myRow["StoreDisplayType"] == "Featured Edition" select myRow;   

     this.gvBestSeller.DataSource = Seller; 
     this.gvBestSeller.DataBind(); // Error 

     this.gvNewRelease.DataSource = newRelease; 
     this.gvNewRelease.DataBind(); // Error 

     this.gvSpecialBook.DataSource = specialBook; 
     this.gvSpecialBook.DataBind(); // Error 

     this.gvFeaturedREdition.DataSource = featuredEdition; 
     this.gvFeaturedREdition.DataBind(); // Error 

回答

2

那是因爲你使用的增值經銷商。您需要使用強類型對象,例如List <>。

public class Book 
{ 
    public string _StoreDisplayType { get; set; } 
    public string _title { get; set; } 
} 

var specialBook = from myRow in StoreDisplayTypeList.AsEnumerable() 
        where (string)myRow["StoreDisplayType"] == "Special Book" 
        select new Book{ 
         _StoreDisplayType = myRow["StoreDisplayType"].ToString(), 
         _title = myRow["Title"].ToString() 
        };  

this.gvSpecialBook.DataSource = specialBook.ToList(); 
this.gvSpecialBook.DataBind(); 
+1

你是對的,只是澄清 - VAR是強類型的,由RHS - 在這種情況下.AsEnumerable是返回一個IEnumerable的結果集(這當然心不是具體的)。 – RPM1984 2010-10-05 08:43:06

+0

Good Point,Jezza!謝謝 – 2010-11-26 10:38:03