Solved

How to do datalist paging using linq to sql and datalist in asp 3.5

Posted on 2008-06-20
1
2,051 Views
Last Modified: 2009-12-16
I m using datalist in my application and i m binding datalist with lisq to sql

liqdatacontext db=new linqdatacontext();
var products=from p in db.products where p.productid>0 select p;
datalist.datasource=products;
datalist.databind();

now how can i do paging in my datalist?
0
Comment
Question by:jbajaj
1 Comment
 
LVL 18

Accepted Solution

by:
Richard Lee earned 500 total points
ID: 21829467
To page with LINQ you can use code such as the following (REF: http://blog.bluecog.co.nz/archives/2007/03/23/simple-paging-with-linq-for-sql/):

private IList<Contribution> GetWithinDays(int days, int skip){

  return ModeratedContributions

    .Where(c => c.AddedOn >= DateTime.Now.AddDays(days))
    .OrderByDescending(c => c.AddedOn)
    .Skip(skip)
    .Take(PageSize)
    .ToList();

}

The above LINQ code should work properly with SQL 2005 & later.



This following reference shows how to maintain the page index, etc. Labels in the markup are used, however it is possible to use ViewState to maintain these details.

REF: http://www.dotnetjohn.com/articles.aspx?articleid=48
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question