码迷,mamicode.com
首页 > Windows程序 > 详细

在C#里分页

时间:2017-07-27 12:43:00      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:source   data   c#   ges   row   wce   tar   next   class   

  1 public partial class frm_SelectGuzhang : Form
  2     {
  3         public string gzCd = "";
  4         public string gzNm = "";
  5         public int maxpage = 0; //总共有多少页
  6         public int maxcount = 0;//有多记录
  7         public int currpage = 0;//当前页
  8         public int PageSize = 8;//每页的大小(记录数)
  9         public string bjCode = string.Empty; //部件编码
 10         IList<T_Base_GuzhangInfo> guzhangList; //故障列表
 11 
 12         /// <summary>
 13         /// 构造函数
 14         /// </summary>
 15         /// <param name="bujancode">部件编码</param>
 16         public frm_SelectGuzhang(string bujancode)
 17         {
 18             InitializeComponent();
 19             try
 20             {
 21                 currpage = 1;
 22                 bjCode = bujancode;
 23                 T_Base_GuzhangInfoImp imp = new T_Base_GuzhangInfoImp();
 24                 guzhangList = imp.GetListByBujianCode(bjCode);
 25                 dgzGuzhang.AutoGenerateColumns = false;
 26                 maxcount = guzhangList.Count();
 27                 maxpage = maxcount % PageSize == 0 ? maxcount / PageSize : maxcount / PageSize + 1;
 28                 BindInfo();
 29             }
 30             catch (Exception)
 31             {
 32 
 33                 throw;
 34             }
 35         }
 36 
 37         /// <summary>
 38         /// 单击单元格
 39         /// </summary>
 40         /// <param name="sender"></param>
 41         /// <param name="e"></param>
 42         private void OrderGrid_CellClick(object sender, DataGridViewCellEventArgs e)
 43         {
 44             try
 45             {
 46                 gzCd = this.dgzGuzhang.CurrentRow.Cells[0].Value.ToString();
 47                 gzNm = this.dgzGuzhang.CurrentRow.Cells[1].Value.ToString();
 48                 this.Hide();
 49             }
 50             catch (Exception)
 51             {
 52 
 53             }
 54         }
 55 
 56         /// <summary>
 57         /// 退出
 58         /// </summary>
 59         /// <param name="sender"></param>
 60         /// <param name="e"></param>
 61         private void btnExit_Click(object sender, EventArgs e)
 62         {
 63             try
 64             {
 65                 this.Close();
 66                 this.Dispose();
 67             }
 68             catch (Exception)
 69             {
 70             }
 71         }
 72 
 73         /// <summary>
 74         /// 前页
 75         /// </summary>
 76         /// <param name="sender"></param>
 77         /// <param name="e"></param>
 78         private void btnPro_Click(object sender, EventArgs e)
 79         {
 80             try
 81             {
 82                 if (currpage > 1)
 83                 {
 84                     currpage = currpage - 1;
 85                 } 
 86                 BindInfo();
 87             }
 88             catch
 89             { }
 90         }
 91 
 92         /// <summary>
 93         /// 绑定数据
 94         /// </summary>
 95         private void BindInfo()
 96         {
 97             try
 98             {
 99                 IList<T_Base_GuzhangInfo> guzhangListNow = guzhangList.Skip((currpage - 1) * PageSize).Take(PageSize).ToList();
100                 this.dgzGuzhang.DataSource = guzhangListNow;
101 
102                 //生成记录
103                 lblPageRecord.Text = string.Format("第{0}页 共{1}页 总数{2}条", currpage, maxpage, maxcount);
104             }
105             catch
106             { }
107         }
108 
109         /// <summary>
110         /// 后页
111         /// </summary>
112         /// <param name="sender"></param>
113         /// <param name="e"></param>
114         private void btnNext_Click(object sender, EventArgs e)
115         {
116             try
117             {
118                 if (currpage*PageSize < maxcount)
119                 {
120                     currpage = currpage + 1;
121                 }
122                 BindInfo();
123             }
124             catch
125             { }
126         }
127     }

 

在C#里分页

标签:source   data   c#   ges   row   wce   tar   next   class   

原文地址:http://www.cnblogs.com/kaifang1028/p/7244173.html

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