本文主要是介绍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();
- }
- })
这篇关于C# datatable分页和 list 分页的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!