c#-datatable Pagination Code

Source: Internet
Author: User

        /// <summary>        ///DataTable Paging and fetching data for specified page numbers/// </summary>        /// <param name= "Dtall" >DataTable</param>        /// <param name= "PageNo" >page number, note: Starting from 1</param>        /// <param name= "PageSize" >number of bars per page</param>        /// <returns>DataTable data with specified page numbers</returns>        PrivateDataTable Getonepagetable (DataTable Dtall,intPageNo,intpageSize) {            varTotalCount =DtAll.Rows.Count; varTotalpage =gettotalpage (TotalCount, pageSize); varCurrentPage =PageNo; CurrentPage= (CurrentPage > Totalpage totalpage:currentpage);//if the pageno is too large, it is more positive pageno=pagecountCurrentPage = (CurrentPage <=0?1: CurrentPage);//if pageno<=0, then change to homepage//----Clone table structure to a new table            varOnepagetable =Dtall.clone (); //----Remove 1 pages of data to a new table            varRowbegin = (CurrentPage-1) *pageSize; varRowend = CurrentPage *pageSize; Rowend= (Rowend > totalcount?)totalcount:rowend);  for(vari = Rowbegin; I <= rowend-1; i++)            {                varNewRow =Onepagetable.newrow (); varOldrow =Dtall.rows[i]; foreach(DataColumn columninchdtall.columns) {newrow[column. ColumnName]=Oldrow[column.                ColumnName];            } onePageTable.Rows.Add (NewRow); }            returnonepagetable; }        /// <summary>        ///returns the total number of pages after paging/// </summary>        /// <param name= "TotalCount" >total number of records</param>        /// <param name= "PageSize" >show number of bars per page</param>        /// <returns>Total Pages</returns>         Public intGettotalpage (intTotalCount,intpageSize) {            varTotalpage = (totalcount/pagesize) + (totalcount% PageSize >0?1:0); returnTotalpage; }

c#-datatable Pagination Code

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.