/*______________________________________________________ // LINQ 2: Using Paging Ron Kessler 2/9/09 _______________________________________________________ */ //Step 1: Make sure to look at the tables I use in my Object Designer and add them. //This form shows how to grab records 10 at a time. //Step 2: Make this the Startup form remember! using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Paging : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //---get the current row from the web server querystring variable defined below int rowNumber = Convert.ToInt32(Request.QueryString["rowNumber"]); //---the row which points to the next group of ten string nextTen = (rowNumber + 10).ToString(); //---each time the page is loaded/created only show the 10 we requested HyperLink1.NavigateUrl = Request.Path + "?rowNumber=" + nextTen; populateGrid(rowNumber); } void populateGrid(int rowNumber) { AdventureWorksDataContext dc = new AdventureWorksDataContext(); var products = from p in dc.Products orderby p.ProductNumber select new { Product_Name = p.ProductNumber, p.Name, Our_Cost = string.Format("{0:n2}",p.StandardCost)}; GridView1.DataSource = products.Skip(rowNumber).Take(10); //this skips past the current group and takes the next 10 GridView1.DataBind(); } }