zoukankan      html  css  js  c++  java
  • DataTable分页

     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
  • 相关阅读:
    【SCOI2012】滑雪
    【NOI2008】假面舞会
    ※初赛知识总结※
    【FJSC2012】足球
    【中山市选2011】杀人游戏
    【SDOI2008】洞穴勘测
    【SNOI2017】炸弹
    【LGOJ1606】白银莲花池
    int类型中为什么负数比正数多了一个数?
    utf8、utf16、utf32之间的格式
  • 原文地址:https://www.cnblogs.com/guzhanyu/p/7422306.html
Copyright © 2011-2022 走看看