Search code examples
c#datatableasp.net-core-2.0ienumerableasenumerable

How to apply skip and take in Datatable Asp.net Core 2.0


Is there any way to apply skip and take in Datatable in asp.net core 2.0. without converting to any class type? I have used stored procedure to get data and convert to Datatable, I want to apply pagination in this Table, how can I do this?


Solution

  • You can not use becuase it does not implement the IEnumerable<T>. But you can do this by using AsEnumerable extension method.

    DataTable dt = new DataTable();
    IEnumerable<DataRow> rows = dt.AsEnumerable().Skip(10).Take(10);
    

    Above solution works for .Net Core version >= 3

    For .Net Core version 2. You need to install the package.

    System.Data.DataExtensions