I have a function that retrieves data from database and add it into list. My list is ready and shows the data but i want paging on that list so that it shows limited records
You can page a list with LINQ, like this:
IList<demodto> GetPage(IList<demodto> list, int page, int pageSize) {
return list.Skip(page*pageSize).Take(pageSize).ToList();
}
For example, suppose each page has 50 records. To get a third page, call
IList<demodto> thirdPage = GetPage(dataList, 3, 50);
Note, however, that applying paging to data in memory makes very little sense: the idea behind paging is to cut down on the time it takes to retrieve your data from the database, and to save some memory by keeping only a single page, which is not going to happen in your case, because all data is retrieved at once.
In order to make paging worth the effort, you need to move it into the database. Change your method to accept page size and number, and use them to change the SQL to retrieve the list for a single page. Don't forget to force ordering on your sql read, otherwise the same data might appear on different pages. Your SQL needs to be modified to support pagination. This is done differently depending on your database. MS SQL Server solution is described in this answer.
_context.skip(5).take(10)
Try to use this one. Better explanation in this question Paging with LINQ for objects
Skip and Take extension methods fits your needs.I don't know how is your page structure but you can use a simple for loop to get values like this:
int recordPerPage = 20;
for(int i=0; i<pageCount; i++)
{
var values = list.Skip(recordPerPage*i).Take(recordPerPage).ToList();
// add values to the page or display whatever..
}