C#的DevExpress控件GridControl实现分页

先看效果图:
在这里插入图片描述

代码如下:

在这里插入代码片
 //页行数
        public int bookSeach_pagesize = 10;
        //当前页
        public int bookSeach_pageIndex = 1;
        //总页数
        public int bookSeach_pageCount;

        //-----图书查询---图书查询分页方法
        public void BookSeach_Pager()
        {
   
            //按钮禁用
            SimpleButton_BookSeach_First.Enabled = false;//首页
            SimpleButton_BookSeach_PrePager.Enabled = false;//上一页
            SimpleButton_BookSeach_NextPager.Enabled = false;//下一页
            SimpleButton_BookSeach_Next.Enabled = false;//尾页
            SimpleLabelItem_BookSeach_AllCount.Text = "图书总数:" + 0 + "本";
            //查询数据库bookSeach_pagesize
            //获取开始的记录数
            int startIndex = (bookSeach_pageIndex - 1) * bookSeach_pagesize + 1;
            //1---10
            //11--20
            //获取结束的记录数
            int endIndex = bookSeach_pageIndex * bookSeach_pagesize;

            //异步执行代码

            if (this.IsHandleCreated) //指示是否关联句柄
            {
   
                this.BeginInvoke(new EventHandler(delegate
                {
   
                    string resultes = sqlcmd.TestPing();
                    if (resultes.Equals("1"))
                    {
   
                        //网络连接成功
                        bool con_falg = sqlcmd.TestConnection(sqlcmd.mysql);
                        if (con_falg)
                        {
   
                            //true连接数据库成功
                            string fisbn, author, iclass, bookname, locals;
                            Bookinfo bf = new Bookinfo();
                            UserList = new List<Bookinfo>();
                            fisbn = f1_f_txt_isbn.Text.Length != 0 ? " and a.isbn like '%" + f1_f_txt_isbn.Text.Trim() + "%'" : "";
                            author = f1_txt_f_author.Text.Length != 0 ? " and author like '%" + f1_txt_f_author.Text.Trim() + "%'" : ""; ;
                            iclass = f1_txt_f_class.Text.Length != 0 ? " and a.classs like '%" + f1_txt_f_class.Text.Trim() + "%'" : "";
                            bookname = f1_txt_f_bookname.Text.Length != 0 ? " and a.bookname like '%" + f1_txt_f_bookname.Text.Trim() + "%'" : "";
                            locals = f1_f_txt_local.Text.Length != 0 ? " and b.locals like '%" + f1_f_txt_local.Text.Trim() + "%'" : "";
                            DataTable rs = new DataTable();

                            //查询总数
                            string sqlcount = "SELECT count(*) FROM bookinfo a RIGHT JOIN localbook b on a.isbn=b.isbn";



                            string sql =
                                "SELECT a.isbn,a.bookname,price,author,publiss,bookimg,b.locals,contents,a.classs FROM bookinfo a RIGHT JOIN localbook b on a.isbn=b.isbn";




                            string sqlwhere = fisbn + author + iclass + bookname + locals;
                            if (sqlwhere != "")
                            {
   

                                sql = sql + " where " + sqlwhere.Substring(4); ;
                                sqlcount = sqlcount +" where " +sqlwhere.Substring(4);
                            }

                            sqlcount = sqlcount + " limit 1";
                            //关闭数据库
                            comm.Close();
                            //总行数
                            int row = comm.GetRecordCount(sqlcount);
                            //关闭数据库
                            Close_DB();
                            SimpleLabelItem_BookSeach_AllCount.Text = "图书总数:" + row + "本";
                            //获取总页数
                            if (row > 0)
                            {
   
                                if (row > bookSeach_pagesize)
                                {
   
                                    if (row % bookSeach_pagesize > 0)
                                    {
   
                                        bookSeach_pageCount = row / bookSeach_pagesize + 1;
                                    }
                                    else
                                    {
   
                                        bookSeach_pageCount = row / bookSeach_pagesize;
                                    }
                                    SimpleLabelItem_BookSeach_Pager.Text = string.Format("第{0}页,共{1}页", bookSeach_pageIndex, bookSeach_pageCount);
                                }
                                else
                                {
   
                                    bookSeach_pageCount = 1;
                                    endIndex = row;
                                    SimpleLabelItem_BookSeach_Pager.Text = string.Format("第{0}页,共{1}页", bookSeach_pageIndex, bookSeach_pageCount);
                                }

                            }
                            else
                            {
   
                                bookSeach_pageCount = 0;
                                SimpleLabelItem_BookSeach_Pager.Text = string.Format("第{0}页,共{1}页", bookSeach_pageIndex, bookSeach_pageCount);
                            }


                            string oisbn = "";
                            string nisbn = "";

                            //关闭数据库
                            Close_DB();
                            //打开数据库
                            comm = Connect_DB(
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

试行

祝您生活愉快!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值