DataGridView 的分页处理

2016-02-19 17:59 34 1 收藏

下面请跟着图老师小编一起来了解下DataGridView 的分页处理,精心挑选的内容希望大家喜欢,不要忘记点个赞哦!

【 tulaoshi.com - Web开发 】

  只是解决DataGridview刷新慢的办法。
  如果要考虑效率,还是结合分页的"存储过程"比较好,只是变通了一下。

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

    1        #region 数据处理
    2         /// summary
    3         /// 得到期初数据
    4         /// /summary
    5         private void getFillDateset()
    6         {
    7             try
    8             {
    9                 //每页显示数
   10                 pageSize = 10;
   11                 //得到最大记录数
   12                 maxRec = dtSource.Rows.Count;
   13                 //共有多少页
   14                 pageCount = (maxRec / pageSize);
   15                 //取余数
   16                 if ((maxRec % pageSize) 0)
   17                 {
   18                     pageCount++;
   19                 }
   20                 //默认第一页
   21                 currentPage = 1;
   22                 recNo = 0;
   23                 LoadPage();
   24             }
   25             catch
   26             {
   27             }
   28         }
   29
   30
   31         /// summary
   32         /// 判断是否数据已经加载
   33         /// /summary
   34         /// returns/returns
   35         private bool CheckFillButton()
   36         {
   37             if (pageSize == 0) return false;
   38             else return true;
   39         }
   40
   41        /// summary
   42         /// 取DataTable的数据
   43        /// /summary
   44         private void LoadPage()
   45         {
   46             int startRec;
   47             int endRec;
   48             DataTable dtTemp;
   49  
   50
   51             dtTemp = dtSource.Clone();
   52             if (currentPage == pageCount) endRec = maxRec;
   53             else endRec = pageSize * currentPage;
   54             startRec = recNo;
   55             for (int i = startRec; i endRec; i++)
   56             {
   57                 dtTemp.ImportRow(dtSource.Rows[i]);
   58                 recNo++;
   59             }
   60             this.dataGridView1.DataSource = dtTemp;
   61         }
   62
   63        /// summary
   64        /// 分页事件(取各个按键的Tag值)
   65        /// /summary
   66        /// param name="sender"/param
   67        /// param name="e"/param
   68         private void changepage(object sender, EventArgs e)
   69         {
   70             if (!CheckFillButton()) return;
   71             int myint = Convert.ToInt16((string)(sender as Button).Tag);
   72             switch (myint)
   73             {
   74                 case 1:
   75                     if (currentPage == 1)
   76                     {
   77                         MessageBox.Show("The frist page now!");
   78                         return;
   79
   80                     }
   81                     currentPage = 1;
   82                     recNo = 0;
   83                     LoadPage();
   84                     break;
   85                 case 2:
   86                     currentPage++;
   87                     if (currentPage pageCount)
   88                     {
   89                         currentPage = pageCount;
   90                         if (recNo == maxRec)
   91                         {
   92                             MessageBox.Show("The last page now!");
   93                             return;
   94                         }
   95                         else
   96                             recNo = pageSize * (currentPage + 1);
   97                     }
   98                     LoadPage();
   99                     break;
  100                 case 3:
  101                     if (currentPage == pageCount)
  102                         recNo = pageSize * (currentPage - 2);
  103                     currentPage--;
  104                     if (currentPage 1)
  105                     {
  106                         MessageBox.Show("The frist page now!");
  107                         currentPage = 1;
  108                         return;
  109                     }
  110                     else
  111                         recNo = pageSize * (currentPage - 1);
  112
  113                     LoadPage();
  114                     break;
  115
  116                 case 4:
  117                     if (!CheckFillButton()) return;
  118                     if (recNo == maxRec)
  119                     {
  120                         MessageBox.Show("The Last page now!");
  121                         return;
  122                     }
  123                     currentPage = pageCount;
  124                     recNo = pageSize * (currentPage - 1);
  125                     LoadPage();
  126                     break;
  127             }
  128
  129         }
  130
  131 #endregion
  http://www.cnblogs.com/azhai/archive/2006/09/18/507624.html

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

来源:http://www.tulaoshi.com/n/20160219/1616539.html

延伸阅读
标签: Web开发
个人会员管理 .closes { font-size:9pt; color:#333333; background-color:#f7f7f7; border:1px solid #CCCCCC;} 个人会员列表 序号 用户名 加入日期 等级 操作 共有 / 条, 当前页 /   [首页] [上一页] ">[首页] &page= ">[上一页] [下一页] [尾页] &page= ">[下一页]  &page= "...
标签: Web开发
From: IECN.Net ; Author: 钟钟 /**  * 分页类构造  * 参数 nTotalList: 总条数  * 参数 nPageSize: 每页显示条数  * 参数 nPageNum: 当前页码  * 参数 sPageUrl: 分页链接的URL,页码以[pn]代替,输出时将被替换为实际...
标签: Web开发
?php//// +----------------------------------------------------------------------+// | 分页类  |// +----------------------------------------------------------------------+// | Copyright (c) 2001 NetFish Software |//...
标签: PHP
  <?php $pagesize = 3;//设置每页显示数目 //计算总记录数 $rs_num = "select count(*) as id from table"; $rs_num = odbc_exec($conn_id,$rs_num); $rs_num = odbc_result($rs_num,"id"); //计算总页数 $pagecount = $rs_num / $pagesize; $pagecount1 = intval($pagecount);//将总页数取整 $comp...
标签: Java JAVA基础
  Jsp如下: ********************** <%@ page language="java" import="java.util.*,java.sql.*" % <%@ page contentType="text/html;charset=gb2312"% <jsp:useBean id="cn" scope="page" class="myConnection.Conn" /<!--引用数据库操作的bean,自己完成,这里不再赘述-- <% int curpage=1;//当前页 int page_record=20...

经验教程

118

收藏

47
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部