/// <summary> /// 分页通用 /// </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) { DataTable newdt = dt.Clone(); int rowbegin = 0; int rowend = 0; if (pageIndex <= 0) { rowbegin = 0; rowend = (pageIndex + 1) * pageSize; } else { rowbegin = (pageIndex - 1) * pageSize; 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 dr = dt.Rows[i]; newdt.ImportRow(dr); } return newdt; }