我的页面加载速度有点慢,因此我想在页面加载完成后在gridview中加载数据。
我想继续使用我的LinqDataSource1_Selecting - 因为当我使用Grid1.DataSource绑定gridview时出现此错误:
无法为未实现ICollection的数据源计算Count。
目前我已尝试使用BackgroundWorker,异步页面和计时器。但我真的不能让他们像我想的那样工作。
这就是我绑定数据的方式:
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
GWportalDataContext db = new GWportalDataContext();
DeliveryTimeRepository dltRep = new DeliveryTimeRepository();
var query = from o in db.Orders
join y in db.OrderLines on o.OrderID equals y.OrderID
join x in db.Products on y.ItemNumber equals x.ItemNumber
where o.AccountNumber == AppSession.CurrentLoginTicket.AccountNumber
select new
{
o.OrderID,
o.AxaptaSalesId,
y.ItemNumber,
Name = x.Name + o.OrderID,
x.ProductFormatName,
y.Quantity,
y.Price,
Status = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(0, dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")),
Levering = dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).Substring(dltRep.getOrderStatus(o.OrderID, o.AxaptaSalesId, y.ItemNumber).LastIndexOf("|")).Replace("|", "")
};
var query2 = from o in db.AxSales
join y in db.AxSaleLines on o.SalesId equals y.SalesId
join x in db.Products on y.ItemNumber equals x.ItemNumber
where o.AccountNumber == AppSession.CurrentLoginTicket.AccountNumber
select new
{
OrderID = o.SalesId,
AxaptaSalesId = o.SalesId,
y.ItemNumber,
Name = x.Name + o.SalesId,
x.ProductFormatName,
y.Quantity,
Price = y.SalesPrice,
Status = dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).Substring(0, dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).LastIndexOf("|")),
Levering = dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).Substring(dltRep.getAxOrderStatus(o.SalesId, y.ItemNumber).LastIndexOf("|")).Replace("|", "")
};
//Query 1 start
var dataToList = query.ToList();
List<object> deletedItems = dataToList.Where(item => orderDeleted(item.OrderID, item.AxaptaSalesId)).Cast<object>().ToList();
var datatoGrid = dataToList.Except(deletedItems);
// Query 1 end
//Query 2 start
var dataToList2 = query2.ToList();
List<object> deletedItems2 = dataToList2.Where(item => axOrderDeleted(item.AxaptaSalesId)).Cast<object>().ToList();
var dataToGrid2 = dataToList2.Except(deletedItems2);
//Query 2 end
var combined = datatoGrid.Union(dataToGrid2);
e.Result = combined;
}
答案 0 :(得分:0)
当您将e.Result
绑定到数据网格时,是否确保将List<Object>
投放回DataGrid.DataSource = (List<Object>)e.Result;
?
e.Result
Object
是ICollection
,未实现datatoGrid.Union(dataToGrid2);
基于OP评论
因为你将其称为
dataGrid.Union(dataToGrid2).ToList();
你只需要做一个
{{1}}