3/// 得到期初数据4/// 5pr...">
论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp.net教程
Tag:静态页面,treeview,gridview,repeater,dataset,sqldatareader,ado.net,上传,三层,ajax,xml,留言本,新闻发布,商城,注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,触发器,socket,form认证,登录,视频教程

DataGridView 的分页处理

文章类别:Asp.net | 发表日期:2008-10-5 22:09:10

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

  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

视频教程列表
文章教程搜索
 
Asp.net推荐教程
Asp.net热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058