开发工具:
文件大小: 8kb
下载次数: 0
上传时间: 2008-12-20
详细说明:
/// /// 获取总页数 /// /// 总记录数 /// /// public static int GetPageCount(int recordcount, int page_size) { int pagecount = 0; if (recordcount % page_size == 0) pagecount = recordcount / page_size; else pagecount = (recordcount / page_size ) + 1; return pagecount; } /**//// /// 获取分页数据 /// /// DATASET /// 每页记录数 /// 页索引 /// 总页数 /// public static DataView GetPagerForView(DataTable dt, int page_size, int pageindex,out string msg) { DataView dv = new DataView(); if (dt != null) { int recordCount = dt.Rows.Count; //总记录数 int page_sum = GetPageCount(recordCount, page_size); if (page_size < dt.Rows.Count)//kl2 :SQL查询函数返回的DATASET { if (page_size == 0)//text_intpase :判断用户设置的分页是否合法 page_size = 10; //recordCount = kl2.Tables[0].Rows.Count;//假设每页只显示1条数据,则共可以显示的页数:pagemark页 if (page_size < 1) { msg = "请将分页项设置在[1-" + dt.Rows.Count.ToString() + "]之间"; } msg = "共" + page_sum.ToString() + "页," + dt.Rows.Count.ToString() + "条";//page_num :lable DataTable page_table = new DataTable();//记录当前正在操作的是哪个表,全局变量,值由查询函数获取 for (int k = 0; k < dt.Columns.Count; k++) { page_table.Columns.Add(dt.Columns[k].ColumnName); } if (dt.Rows.Count != 0 && page_size < dt.Rows.Count) { page_table.Clear(); try //普通页面显示 { page_table.Clear(); for (int i = 0; i < page_size; i++) { page_table.Rows.Add(dt.Rows[i + (pageindex * page_size)].ItemArray); } } catch //最后不足一个页面的显示 { page_table.Clear(); try { for (int s = 0; s < recordCount - (pageindex * page_size); s++) { page_table.Rows.Add(dt.Rows[s + (pageindex * page_size)].ItemArray); } } catch { } } msg += " 当前第" + (pageindex + 1).ToString() + "页"; } dv = page_table.DefaultView; } else { dv = dt.DefaultView; msg = "共1页," + dt.Rows.Count.ToString() + "条"; msg += " 当前第" + (pageindex + 1).ToString() + "页"; } return dv; } else { msg = "没有数据!"; return null; } } Form中调用: Code private DataTable GetDicData()//获取所有据 { BLLB_CommunitDIC bcdicBll = new BLLB_CommunitDIC(); if (trvDic.SelectedNode != null) { if (trvDic.SelectedNode.Parent == null) { return null; } else { int areaid = Convert.ToInt32(trvDic.SelectedNode.Tag); return FCT.Common.PublicMethods.ConvertToDataSet(bcdicBll.GetAll(areaid)).Tables[0]; } } else return null; } //根据页索此获取数据 private void InitData(int pageindex) { DataTable dt = GetDicData(); string msg; if (dt != null && dt.Rows.Count > 0) { dgrvDic.AutoGenerateColumns = false; dgrvDic.DataSource = Public.CustomerPager.GetPagerForView(dt, 10, pageindex, out msg); toolStripLabel18.Text = msg; } } Code 分页事件#region 分页事件 private void toolStrip7_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Tag != null) { this.Cursor = Cursors.WaitCursor; int _currentPageIndex = 1; DataTable dt = GetDicData(); int pagecount = 0; if (dt != null) pagecount = Public.CustomerPager.GetPageCount(dt.Rows.Count, 10); if (toolStripTextBox6.Text != "") { try { _currentPageIndex = Convert.ToInt32(toolStripTextBox6.Text); } catch { _currentPageIndex = 1; } } switch (e.ClickedItem.Tag.ToString()) { case "First": _currentPageIndex = 1; break; case "Prev": _currentPageIndex = _currentPageIndex - 1; break; case "Next": _currentPageIndex = _currentPageIndex + 1; break; case "Last": _currentPageIndex = pagecount; break; default: this.Cursor = Cursors.Default; break; } InitData(_currentPageIndex - 1); if (_currentPageIndex == 1) { toolStripTextBox6.Text = "1"; this.toolStripButton25.Enabled = false; this.toolStripButton26.Enabled = false; this.toolStripButton27.Enabled = true; this.toolStripButton28.Enabled = true; } else { if (_currentPageIndex < pagecount && _currentPageIndex >= 1) { toolStripTextBox6.Text = _currentPageIndex.ToString(); this.toolStripButton25.Enabled = true; this.toolStripButton26.Enabled = true; this.toolStripButton27.Enabled = true; this.toolStripButton28.Enabled = true; } else if (_currentPageIndex == pagecount) { toolStripTextBox6.Text = pagecount.ToString(); this.toolStripButton25.Enabled = true; this.toolStripButton26.Enabled = true; this.toolStripButton27.Enabled = false; this.toolStripButton28.Enabled = false; } else { this.toolStripButton25.Enabled = false; this.toolStripButton26.Enabled = false; this.toolStripButton27.Enabled = false; this.toolStripButton28.Enabled = false; } } this.Cursor = Cursors.Default; } 84 #endregion ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.