Solved

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

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now