• Datatable分页


    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Data;
    
    /// <summary>
    ///Page 的摘要说明
    /// </summary>
    public class PageList
    {
        public PageList()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 对DataTable进行分页,起始页为1
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <returns></returns>
        public static DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
        {
            if (PageIndex == 0)
                return dt;
            DataTable newdt = dt.Copy();
            newdt.Clear();
    
            int rowbegin = (PageIndex - 1) * PageSize;
            int rowend = PageIndex * PageSize;
    
            if (rowbegin >= dt.Rows.Count)
                return newdt;
    
            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;
        }
    
        /// <summary>
        /// 获取总页数
        /// </summary>
        /// <param name="sumCount">结果集数量</param>
        /// <param name="pageSize">页面数量</param>
        /// <returns></returns>
        public static int getPageCount(int sumCount, int pageSize)
        {
            int page = sumCount / pageSize;
            if (sumCount % pageSize > 0)
            {
                page = page + 1;
            }
            return page;
        }
    
    }

    来源:http://blog.csdn.net/willianyy/article/details/5734486

    慎于行,敏于思!GGGGGG
  • 相关阅读:
    WebServices Get
    字符出现次数
    正则
    防止AutoPost
    转双问号,单问号
    GetData
    UpdatePanel
    字居中
    C# 面向对象之多态
    C# 委托之把委托从委托链(多播委托)移除
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/4103764.html
Copyright © 2020-2023  润新知