title: Databind Grid LINQ Asynchronous ASP.NET C#
body: <p>I have a page loading a bit slow, and because of that I want to load the data in the gridview AFTER the page is done loading.</p>
  
  <p>I would like to, keep using my LinqDataSource1_Selecting - since I get this error when I bind the gridview with Grid1.DataSource:</p>
  
  <blockquote>
    <p>Cannot compute Count for a data source that does not implement ICollection.</p>
  </blockquote>
  
  <p>For now I've tried using BackgroundWorker, Asynchronous Pages and a timer. But I can't really get them too work like I want to.</p>
  
  <p>This is how I'm binding my data:</p>
  
  <pre><code>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&lt;object&gt; deletedItems = dataToList.Where(item =&gt; orderDeleted(item.OrderID, item.AxaptaSalesId)).Cast&lt;object&gt;().ToList();
          var datatoGrid = dataToList.Except(deletedItems);
          // Query 1 end
  
          //Query 2 start
          var dataToList2 = query2.ToList();
          List&lt;object&gt; deletedItems2 = dataToList2.Where(item =&gt; axOrderDeleted(item.AxaptaSalesId)).Cast&lt;object&gt;().ToList();
          var dataToGrid2 = dataToList2.Except(deletedItems2);
          //Query 2 end
  
          var combined = datatoGrid.Union(dataToGrid2);
          e.Result = combined;
  }
  </code></pre>