C# datatable分页函数和 list 分页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize, out int recound) { if (dt == null || dt.Rows == null || dt.Rows.Count <= 0) { recound = 0; return null; } if (PageIndex < 1) { PageIndex = 1; } else if (PageIndex > 1 || PageIndex == 1) { PageIndex = PageIndex + 1; } DataTable newdt = dt.Copy(); newdt.Clear(); recound = dt.Rows.Count; 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; } //生成新的DataTable 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; } |
take-skip分页 针对集合 | mapList.List = mapList.List.Skip((oldpageIndex – 1) * oldpageSize).Take(oldpageSize).ToList(); | |
附加://模糊查询添加回车即查询 | $(“#txtKeywords”).bind(“keyup”, function (e) {
if (e.keyCode == 13) { gv.reload(); } }) |
创作不易,用心坚持,请喝一怀爱心咖啡!继续坚持创作~~
