Pagination the able and generate a new datatable

Source: Internet
Author: User
///   <Summary>
/// Pagination the able and generate a new datatable
///   </Summary>
///   <Param name = "DT"> Original datatable </Param>
///   <Param name = "pageindex"> Page N required </Param>
///   <Param name = "pagesize"> Number of pages per page </Param>
///   <Returns> New able </Returns>
Public Datatable getpagedtable (datatable DT, Int Pageindex, Int Pagesize)
{
If (Pageindex =   0 )
{
Return DT;
}
Datatable newdt = DT. Copy ();
Newdt. Clear ();
// Start row
Int Rowbegin = (Pageindex -   1 ) * Pagesize;
// End row
Int Rowend = Pageindex * Pagesize;

If(Rowbegin> =DT. Rows. Count)
{
ReturnNewdt;
}

If (Rowend > DT. Rows. Count)
{
Rowend = DT. Rows. count;
}
// Generate a new able
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;
}

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.