C#中的分页技术

1、页数=
--记录条数%每页条数==0    记录条数/每页条数
--否则   记录条数/每页条数+1

2、第N页娴熟第几条记录(记录从0开始)
--(N-1)*每页条数 =< 序号 < N*每页条数

 

Code
public class PageController{

    
private ArrayList bigList;     //大的集合,外界传入
    private int curentPageIndex=1;    //当前页号
    private int countPerpage =5;        //每页条数,外界可以传
    private ArrayList smallList;    //小的集合,返回
    private int pageCount;    //页数
    private int recordCount //记录条数
    private int prePageIndex;    //上一页序号
    private int nextPageIndex;    //下一页序号
    private boolean firstPage;    //是否是第一页    
    private boolean lastPage;    //是否是最后一页

public void setCurrentPageIndex(int currentPageIndex)
{

this.currentPageIndex=currentPageIndex;    

//上一页,下一页确定
prePageIndex=currentPageIndex-1;
nextPageIndex
=currentPageIndex+1;

//是否是第一页,最后一页
if(currentPageIndex==1)
{
fistPage
=true;
}
else
{
fistPage
=false;
}
if(currentPageIndex==pageCount)
{
lastPage
=true;
}
else
{
lastPage
=false;
}
筛选工作
smallList
=new ArrayList();
for(int i=(currentPageIndex-1)*countPerpage;i<currentPageIndex*countPerpage && i<recordCount;i++)
{
smallList.add(bigList.
get(i));
}
}


}

public void setBigList(ArrayList bigList)

{
this.bigList=bigList;

//计算条数
recordCount=biglist.size();

//计算页数
if(recordCount%countPerpage==0)
{
pageCount
=recordCount/countPerpage;
}
else
{
pageCount
=recordCount/countPerpage+1;
}
}


//在ACTION中    第一页
String str=request.getParameter("PageIndex");
if(str==null)
{
str
="1";
}
int currentPageIndex=Integer.parseInt(str);

PaeController pc
=()PaeController request.getAttribute("pc"); 
if(pc==null)
{
pc
=new PaeController();
StudentDao studentDao
=new StudentDao();
ArrayList stus
=studentDao.queryStu();
pc.setBigList(stus);
request.setAttribute(
"pc",pc);
}
pc.setCurrentPageIndex(currentPageIndex);

 

//显示页面

 

Code
<html:link action="/query.do?PageIndex=1">首页</html:link>

<logic:equal name="pc" property="firstPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="prePageIndex">上一页</html:link>
</logic:equal>
<logic:equal name="pc" property="lastPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="nextPageIndex">下一页</html:link>
</logic:equal>
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="pageCount">尾页</html:link>

 

 

 

转载于:https://www.cnblogs.com/ylsoftd/articles/1420107.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值