我正在从 SQL 数据库检索数据。我想分割记录并将其绑定在三个不同的网格中。在应用分页之前一切工作正常。我收到数据源不支持服务器端数据分页。错误
代码:
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
那是因为你正在使用vars。您需要使用强类型对象,例如 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();