首页 > 代码库 > C# DataTable分页函数
C# DataTable分页函数
/// <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; }
C# DataTable分页函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。