我有一個GridView,一次只顯示50條記錄,通過分頁。如果我將它綁定到包含150條記錄的源文件,它就像魅力一樣工作,但是當記錄大小急劇增加到10,00000時,它花費了很長時間才能加載數據。所以,我想知道是否有任何方法只是加載50記錄在一個可見的時間?綁定GridView有很多記錄
我想是懶加載或WPF中的虛擬化堆棧 面板的功能。
我這是怎麼結合到GridView -
private void LoadCustomers()
{
if (Cache["CustomersData"] == null)
{
Business.Customers customers = Business.Customers.GetAllCustomer();
Cache["CustomersData"] = customers;
}
this.customerGridView.DataSource = Cache["CustomersData"];
this.customerGridView.DataBind();
}
下面是從DB-
獲取數據public static Customers GetAllCustomer(int index)
{
Customers customers = new Customers();
NShop_SmallEntities data = new NShop_SmallEntities();
var dbCustomers = (from c in data.Customers
select c).OrderBy(c=> c.CustomerId).Skip(index * 50).Take(50);
foreach (var dbCustomer in dbCustomers)
{
customers.Add(Customer.GetCustomer(dbCustomer));
}
return customers;
}
public static Customer GetCustomer(DAL.Customer dbCustomer)
{
return new Customer()
{
CustomerId = dbCustomer.CustomerId,
FirstName = dbCustomer.FirstName,
LastName = dbCustomer.LastName,
Email = dbCustomer.Email,
DOB = dbCustomer.DOB,
City = dbCustomer.City,
State = dbCustomer.State,
PostalCode = dbCustomer.PostalCode,
Country = dbCustomer.Country,
OrderCount = dbCustomer.Orders.Count()
};
}
什麼樣的DB的:SQL Server中,AS400 ...... – IrishChieftain 2011-04-08 19:40:53
數據庫是SQL服務器... – 2011-04-08 19:49:08