一个分页方法的代码
private void ShowRecord(int RecordCount,int CurrentPage)
{
int CurrentRC;
TableRow Tr=new TableRow();
TableCell Tc=new TableCell();
TotalPage=RecordInfo.GetRecordCount()/RecordCount+1;
CurrentRC=RecordInfo.GetRecordCount()-(CurrentPage-1)*RecordCount;
if(CurrentRC>RecordCount) CurrentRC=RecordCount;
for(int i=(CurrentPage-1)*RecordCount;i<CurrentRC+(CurrentPage-1)*RecordCount;i++)
{
Tc.Controls.Add(new LiteralControl("<table><tr><td>"+RecordInfo.GetInfoTitle(i)+"</td></tr></table>")); //Table UI Code
Tr.Cells.Add(Tc);
TitleTable.Rows.Add(Tr);
}
//-----PageLink---------
string FirstPageStr,LastPageStr,ForwardStr,BackStr;
int PageStart,PageOver;
FirstPageStr="首页";
LastPageStr="尾页";
ForwardStr="下一页";
BackStr="上一页";
TableRow Trow=new TableRow();
TableCell Tcell=new TableCell();
Tcell.Controls.Add(new LiteralControl(CurrentPage.ToString()+"/"+TotalPage.ToString()+" ["));
PageStart=CurrentPage/11*10+1;
if(PageStart==TotalPage/11*10+1)
PageOver=TotalPage;
else
PageOver=PageStart+9;
for(int i=PageStart;i<=PageOver;i++)
Tcell.Controls.Add(new LiteralControl("<a href=InfoTitle.aspx?pid="+i.ToString()+"'><b>"+i.ToString()+"</b></a> "));
if(CurrentPage!=1) BackStr="<a href='InfoTitle.aspx?pid="+(CurrentPage-1).ToString()+"'>"+BackStr+"</a>";
if(CurrentPage!=TotalPage) ForwardStr="<a href='InfoTitle.aspx?pid="+(CurrentPage+1).ToString()+"'>"+ForwardStr+"</a>";
Tcell.Controls.Add(new LiteralControl("] "+BackStr+" "+ForwardStr+" | <a href='InfoTitle.aspx?pid=1'>"+FirstPageStr+"</a> <a href='InfoTitle.aspx?pid="+TotalPage+"'>"+LastPageStr+"</a>"));
Trow.Cells.Add(Tcell);
PageLink.Rows.Add(Trow);
}此方法是直接放在UI层的,感觉应该不太正规,现在就先用到,下次又做东西时再重构了~~~HOHO~~

浙公网安备 33010602011771号