C # datatable pagination processing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.