码迷,mamicode.com
首页 > 其他好文 > 详细

DataTable分页

时间:2017-08-24 13:35:43      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:play   数据   return   count   display   大小   i++   summary   data   

技术分享
 1    /// <summary> 
 2         /// DataTable分页 
 3         /// </summary> 
 4         /// <param name="dt">DataTable</param> 
 5         /// <param name="PageIndex">页索引,注意:从1开始</param> 
 6         /// <param name="PageSize">每页大小</param> 
 7         /// <returns>分好页的DataTable数据</returns>              第1页        每页10条 
 8         public static DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize) {
 9             if (PageIndex == 0) { return dt; }
10             DataTable newdt = dt.Copy();
11             newdt.Clear();
12             int rowbegin = (PageIndex - 1) * PageSize;
13             int rowend = PageIndex * PageSize;
14 
15             if (rowbegin >= dt.Rows.Count) { return newdt; }
16 
17             if (rowend > dt.Rows.Count) { rowend = dt.Rows.Count; }
18             for (int i = rowbegin; i <= rowend - 1; i++) {
19                 DataRow newdr = newdt.NewRow();
20                 DataRow dr = dt.Rows[i];
21                 foreach (DataColumn column in dt.Columns) {
22                     newdr[column.ColumnName] = dr[column.ColumnName];
23                 }
24                 newdt.Rows.Add(newdr);
25             }
26             return newdt;
27         }
28 
29         /// <summary> 
30         /// 返回分页的页数 
31         /// </summary> 
32         /// <param name="count">总条数</param> 
33         /// <param name="pageye">每页显示多少条</param> 
34         /// <returns>如果 结尾为0:则返回1</returns> 
35         public static  int PageCount(int count, int pageye) {
36             int page = 0;
37             int sesepage = pageye;
38             if (count % sesepage == 0) { page = count / sesepage; } else { page = (count / sesepage) + 1; }
39             if (page == 0) { page += 1; }
40             return page;
41         } 
View Code

 

DataTable分页

标签:play   数据   return   count   display   大小   i++   summary   data   

原文地址:http://www.cnblogs.com/guzhanyu/p/7422306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!