Search code examples
c#datatablerowfilter

How do I Access separate pages of DataTable rows


I have a DataTable with a large resultset.
This DataTable is used to generate multiple pages in a PDF (one for each row in the DataTable).

After a certain number of rows, the PDF generation takes too long, so I want to provide a list of hyperlinks for the end user to generate separate PDFs for each set of rows,
i.e. Set 1 (Rows 0-90), Set 2 (Rows 91-181), etc.

I want to be able to filter the original DataTable whenever I generate a PDF for that set of rows. I know that GridViews offer Paging capability, but I don't want to plop the data into a gridview unnecessarily.

What I am hoping for is some kind of RowFilter where I can say:

_dt.RowFilter = "Rows(0-90)"

Does anyone know of such a feature of DataTables (using .NET 3.5)?
Or can anyone offer another solution? Thanks


Solution

  • Try this - use the AsEnumerable extension method, then use LINQ to query the rows you need.

    dataTable.AsEnumerable().Take(90);
    

    Page 2:

    dataTable.AsEnumerable().Skip(90).Take(90);