给大家分享下我自认为GridView 最简单的分页,

前台代码:

        
       
            <%# Eval("title") %>
               
               
           

            <%# Eval("conter") %>
               
               
           

           
               
                   下载
               

               
               
               
           

       

       
   

     


        首页
        上一页
        下一页
        尾页
   

后台代码:

          protected void Bind()
        {
            //定义记录总数
            //int total;
            //定义当前页码
            int pageindex;
            //获取当前页码(从查询字符串中获取)
            if (!int.TryParse(Request.QueryString["page"], out pageindex))
            {
                pageindex = 1;
            }
            

            //11为显示的当前页显示11条记录。
            //获取指定类别,指定页码的数据,并进行绑定显示
            GridView1.DataSource = DownManager.GetsPage(pageindex, 11);
            GridView1.DataBind();
            //计算总的页数
            int totalpage = (int)Math.Ceiling(Convert.ToDouble(DownManager.getsNum()) / 11F);
            //NavigateUrl 获取或者设置链接目标
            //设置分页
            HyperLink1.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"];
            HyperLink2.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + (pageindex > 1 ? pageindex - 1 : 1);
            HyperLink3.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + (pageindex < totalpage ? pageindex + 1 : totalpage);
            HyperLink4.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + totalpage;
           
        }

注:page  id 值的获取。