Solved

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

Posted on 2008-06-20
1
2,069 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

756 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