View Single Post
  #8 (permalink)  
Old March 21st, 2008, 11:06 AM
jimibt jimibt is offline
Friend of Wrox
 
Join Date: Mar 2007
Location: Creetown, UK
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default

Quote:
quote:Originally posted by dparsons
 Paging is quite simple using LINQ, a basic method might be something like this:

private void BindDataSource(int rowNumber)
{
TBHDataContext ctx = new TBHDataContext();
var articles = from a in ctx.Articles
                 where a.ArticleID >= 1;
gv.DataSource = articles.Skip(rowNumber).Take(15);
gv.DataBind();
}

The Skip() and Take() methods is where the magic happens. Take(15) returns the first 15 records starting from the Row position defined in Skip(). So if rowNumber = 1 then Take(15) would return the first 15 records in your result set.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
doug, i presume there's a way to do sorting on the linq object as well?? (i.e. if clicking on column headers etc..)

jimi

http://www.originaltalent.com