title: asp.net gridview paging and sorting with linq to sql custom linq statement
body: <p>Ok, I know this cant really be that hard, but im having trouble finding any info. I have a gridview on the page that i am filling with data based on a user selected date range(a dropdown list). When the user clicks the button i fill the gridview and display it. This is all done using Linq to Sql. I need to impliment paging and sorting as well. Help PLEASE!!! Below is my button click event... i am open to any suggestions to get this working</p>
  
  <pre><code>protected void btnGenerate_Click(object sender, EventArgs e)
       {
           int dateRange =0;
           if (rbDateList.Checked)
           {
               switch (ddlDateRange.SelectedIndex)
               {
                   case 0:
                       dateRange = 30;
                       break;
                   case 1:
                       dateRange = 60;
                       break;
                   case 2:
                       dateRange = 90;
                       break;
                   default:
                       dateRange = 30;
                       break;
               }
           }
           GYTDataContext gt = new GYTDataContext();
           var productList = from o in gt.PurchaseOrderDetails
                             join p in gt.Products on o.ProductId equals p.ProductId
                             join h in gt.PurchaseOrderHeaders on o.PurchaseOrderId equals h.PurchaseOrderId
                             where h.OrderDate&gt;DateTime.Now.AddDays(-dateRange)
                             group o by o.ProductId into orderedItems
                             select new
                             {
                                 orderedItems.Key,
                                 QuantityOrdered = orderedItems.Sum(s =&gt; s.OrderQuantity)
                             };
           var totalOrderInfo = from p in productList
                                join prod in gt.Products
                                on p.Key equals prod.ProductId
                                select new
                                {
                                    prod.Reference,
                                    UnitPrice = prod.Price,
                                    prod.ManufacturerProductId,
                                    p.QuantityOrdered,
                                    TotalCost = prod.Price * Convert.ToInt32(p.QuantityOrdered)
                                };
  
          gvOrderReport.DataSource = totalOrderInfo;
           gvOrderReport.DataBind();
           gvOrderReport.Visible = true;
  </code></pre>