zoukankan      html  css  js  c++  java
  • web程序入门三(分页)

    分页:

    概念:

    pageSize = 5    // 每页5条数据

    psgeCount =Convert.toInt32( Math.Ceiling(recordCount*1.0/pageSize))    //共多少页

    Math.Ceiling() // 地板除法,返回等于或大于该数的最小整数

    pageIndex  //当前页码值  (1,pageCount)

    取数据:

    根据当前页码值来动态显示数据

    select  row_number()  over (order by  id ) as  num,  *  from userInfo;

    查询共有多少列

    row_number()是一个方法

    select  *  from( row_number()  over (order by  id ) as  num,  *  from userInfo ) as  t 

    where  t.num>=20  and  t.num<=24; 

     通过这条sql语句来查询当前数据

    根据当前页码,计算要显示的内容

    页码通过URL传参 这样后端可以从URL中获取当前页数

    下面页码处处理:

    <a href ="list.aspx?pageindex=1">首页</a>

    <a href ="list.aspx?pageindex=<%=pageindex<=1?1:pageindex-1%>">上一页</a>     pageindex 是后端传到前端的数据

    <a href ="list.aspx?pageindex=<%=pageindex>=20?20:pangeindex+1%>">下一页</a>     20是假定的总页码20页

    <a href ="list.aspx?pageindex=20">尾页</a>

    改进 版当前页是第一页时 不显示首页和上一页连接

    if (pageindex==1)

    {

    <a href ="list.aspx?pageindex=<%=pageindex>=20?20:pangeindex+1%>">下一页</a>     20是假定的总页码20页

    <a href ="list.aspx?pageindex=20">尾页</a>

    }

    else if(pageindex==20)

    {

    <a href ="list.aspx?pageindex=1">首页</a>

    <a href ="list.aspx?pageindex=<%=pageindex<=1?1:pageindex-1%>">上一页</a> 

    }

    else

    {

    <a href ="list.aspx?pageindex=1">首页</a>

    <a href ="list.aspx?pageindex=<%=pageindex<=1?1:pageindex-1%>">上一页</a>     pageindex 是后端传到前端的数据

    <a href ="list.aspx?pageindex=<%=pageindex>=20?20:pangeindex+1%>">下一页</a>     20是假定的总页码20页

    <a href ="list.aspx?pageindex=20">尾页</a>

    }

    数字页码:

    页面上最多显示10个数字页码       起始位置-------终止位置

    1…………10        (看百度下面分页)

    3…………12         

    5…………14       

    起始位置 页码  start =  pageIndex-5 <1?1:pageindex-5

    终止位置  页码  end  =  pageindex+4      

     if (end>20)              20为假定的总页数20

    {

    end=20;

    start=end-9>1?end-9:1;   这一条是确定,没有10页,或者end是最后一页时,页面无法显示10个页码

    }

    这个不需要更改后端代码,只需要更改前端显示

  • 相关阅读:
    centos-docker安装及基本使用
    List集合-03.Vector
    List集合-02.LinkedList
    List集合-01.ArrayList
    常用图像处理方法
    git使用
    bug记录
    bash vim等常用命令
    python常用
    MTCNN试用
  • 原文地址:https://www.cnblogs.com/mayyan/p/7908556.html
Copyright © 2011-2022 走看看