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.
[edit]: The obvious question might be: "Thats great but how do I know what to skip by?" In the case of the GridView if you handle the PageIndexChanging event you could do something like this:
protected void gv_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv.PageIndex = e.NewPageIndex;
BindDataSource(GetNextPage(e.NewPageIndex , gv.PageSize));
}
private int GetNextPage(int pageIndex, int pageSize)
{
if(pageIndex == 1){ return 1; }
else
{
return ((pageIndex * pageSize) - (pageSize - 1));
}
}
================================================== =========
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
================================================== =========