Public DataTable getpagedtable (DataTable dt, int PageIndex, int PageSize)//pageindex represents the first few pages, PageSize represents the number of records per page
{
if (PageIndex = = 0)
Return dt;//0 page represents the data for each page and returns directly
DataTable NEWDT = dt. Copy ();
Newdt. Clear ();//copy DT Framework
int rowbegin = (PageIndex-1) * PageSize;
int rowend = PageIndex * PageSize;
if (rowbegin >= dt. Rows.Count)
Return newdt;//the number of source data records is less than or equal to the records to be displayed, directly back to DT
if (rowend > dt. Rows.Count)
rowend = dt. Rows.Count;
for (int i = rowbegin; I <= rowend-1; i++)
{
DataRow NEWDR = Newdt. NewRow ();
DataRow dr = dt. Rows[i];
foreach (DataColumn column in dt. Columns)
{
Newdr[column. ColumnName] = Dr[column. ColumnName];
}
Newdt. Rows.Add (NEWDR);
}
return NEWDT;
}
The second way
Public datarow[] Gettablerows (DataTable dtalleas, int pageindex,int PageSize)
{
var rows = dtalleas.rows.cast<datarow> ();
var currows = rows. Skip (PageIndex). Take (PageSize). ToArray ();
}
C # datatable pagination processing