asp.netpaginationlinq-to-sqldatalist

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


I'm using datalist in my application and i'm binding datalist with lisq to sql

dim db=new linqdatacontext(); var products=from p in db.products select p; datalist.datasource=products; datalist.databind();

now how can i do paging in my datalist?


Solution

  • Use keywords Take and Skip

    var products=from p in db.products select p 
                 Skip NUMER_TO_START Take NUMBER_TO_TAKE
    

    Very simple, consider there are 1000 rows of results in p, and Skip 50 means you are not going take results #1-#50, and it will give you results from #51, Take is simply how many records you need.