Search code examples
c#xmllinqpaginationvirtualmode

How to customize a specific code for pagination when working with datagridview virtual mode on


i am reading a xml file instead of database table and doing pagination this way

XDocument document = XDocument.Load(xmlFilePath);
var query = from r in document.Descendants("orders")
select new
{
    OrderID = r.Element("OrderID").Value,
    CustomerID = r.Element("CustomerID").Value,
    EmployeeID = r.Element("EmployeeID").Value
};
query = query.OrderBy(sortColumn + " " + OrderDirection);
query = query.Skip(lowerPageBoundary - 1 * rowsPerPage).Take(rowsPerPage);

but the problem is lowerPageBoundary value is controller by another class which i got from MSDN link https://msdn.microsoft.com/en-us/library/ms171624.aspx?f=255&MSPPError=-2147217396

i am following the same code which MSDN gave but my pagination routine is not compatible for the below code and not working too.

query = query.Skip(lowerPageBoundary - 1 * rowsPerPage).Take(rowsPerPage);

first time lowerPageBoundary is 0 so skip has 0 as value and take has 16 as value and when the same line execute second time lowerPageBoundary is 16-16=0

so it my request that some one please see the MSDN link which i gave here and see Cache class which is controlling the value for lowerPageBoundary and suggest me how to customize LINQ skip and take for the MSDN code scenario.

thanks


Solution

  • It seems that you don't have to deduct rowsPerPage from lowerPageBoundary. I.e. for the first page lowerPageBoundary = 0, rowsPerPage = 16, so you need to skip 0 records and take 16. For the second page lowerPageBoundary = 16, so you need to skip 16 rows, and then take 16 next ones etc. I.e. you should use the next code:

    query = query.Skip(lowerPageBoundary).Take(rowsPerPage);