C# datatable分页和 list 分页
datatable分页 |
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(); } }) |