Solved

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

Posted on 2008-06-20
1
2,060 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

856 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