Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Read about why website design really matters in today's demanding market.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

743 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

17 Experts available now in Live!

Get 1:1 Help Now