zoukankan      html  css  js  c++  java
  • C# 翻页设计:首页,上一页,下一页,末页 ,跳转

     int pageSize = 0;     //每页显示行数
            int nMax = 0;         //总记录数
            int pageCount = 0;    //页数=总记录数/每页显示行数
            int pageCurrent = 0;   //当前页号
            int nCurrent = 0;      //当前记录行       
    private void Bind()
            {
                //td = um.dataAll();
                pageSize = 30;      //设置页面行数
                nMax = td.Rows.Count;
                pageCount = (nMax / pageSize);    //计算出总页数
                if ((nMax % pageSize) > 0) pageCount++;
                pageCurrent = 1;    //当前页数从1开始
                nCurrent = 0;       //当前记录数从0开始
                LoadData();
    
            }
    private void LoadData()
            {
                int nStartPos = 0;   //当前页面开始记录行
                int nEndPos = 0;     //当前页面结束记录行
                DataTable dtTemp = td.Clone();   //克隆DataTable结构框架
    
                if (pageCurrent == pageCount)
                {
                    nEndPos = nMax;
                }
                else
                {
                    nEndPos = pageSize * pageCurrent;
                }
    
                nStartPos = nCurrent;
                lblPageCount.Text = "共 " + pageCount.ToString() + " 页";
                txtCurrentPage.Text = Convert.ToString(pageCurrent);
    
    
                //从元数据源复制记录行
                if (td.Rows.Count > 0)
                {
                    for (int i = nStartPos; i < nEndPos; i++)
                    {
                        dtTemp.ImportRow(td.Rows[i]);
                        nCurrent++;
                    }
                }
               
                dataGridView1.DataSource = dtTemp;
                //datagridView默认不选中行
               
                int endC = td.Rows.Count;
                if (endC > pageSize * pageCurrent)
    
                    endC = pageSize * pageCurrent;
                int k = 0;
    
                for (int i = pageSize * (pageCurrent - 1) + 1; i <= endC; i++)
                {
    
    
                    dataGridView1.Rows[k].HeaderCell.Value = i.ToString();
                    k++;
                }
               
               
            }
    private void up_Click(object sender, EventArgs e)
            {
                pageCurrent--;
                if (pageCurrent <= 0)
                {
                    MessageBox.Show("已经是第一页,请点击“下一页”查看!");
                    return;
                }
                else
                {
                    nCurrent = pageSize * (pageCurrent - 1);
                }
                LoadData();
    
            }
    
            private void down_Click(object sender, EventArgs e)
            {
                pageCurrent++;
                if (pageCurrent > pageCount)
                {
                    MessageBox.Show("已经是最后一页,请点击“上一页”查看!");
                    return;
                }
                else
                {
                    nCurrent = pageSize * (pageCurrent - 1);
                }
                LoadData();
    
            }
    
            private void first_Click(object sender, EventArgs e)
            {
                pageCurrent = 1;
                nCurrent = pageSize * (pageCurrent - 1);
                LoadData();
    
            }
    
            private void end_Click(object sender, EventArgs e)
            {
                pageCurrent = pageCount;
                nCurrent = pageSize * (pageCurrent - 1);
                LoadData();
            }
    
            private void skip_Click(object sender, EventArgs e)
            {
                int CurrentP = Convert.ToInt32(txtCurrentPage.Text.ToString());
                if (CurrentP > pageCount)
                {
                    MessageBox.Show("超过最大页数,请重新输入");
                    return;
                }
                else
                {
                    pageCurrent = CurrentP;
                    nCurrent = pageSize * (pageCurrent - 1);
                    LoadData();
                }
            }
    
  • 相关阅读:
    如何在工作组设置中将本地策略应用于 Windows Server 2000 上除管理员以外的所有用户
    中小规模NT网的安全策略(一)
    Windows 2000 中的域安全性策略
    HOW TO:在 Windows 2000 的“安全模板”管理单元中定义安全模板
    Windows 2000 安全配置工具
    组策略特性集的渐进指南
    域级别策略
    Windows命令
    winForm base64编码转换 上传文件到web服务器
    php定界符方便好用
  • 原文地址:https://www.cnblogs.com/zzlp/p/4118514.html
Copyright © 2011-2022 走看看