一个分页方法的代码



        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()+"&nbsp;&nbsp;&nbsp;&nbsp;["));
            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>&nbsp;"));
            
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("]&nbsp;&nbsp;&nbsp;"+BackStr+"&nbsp;&nbsp;"+ForwardStr+"&nbsp;|&nbsp;<a href='InfoTitle.aspx?pid=1'>"+FirstPageStr+"</a>&nbsp;&nbsp;<a href='InfoTitle.aspx?pid="+TotalPage+"'>"+LastPageStr+"</a>"));
            Trow.Cells.Add(Tcell);
            PageLink.Rows.Add(Trow);
        }


此方法是直接放在UI层的,感觉应该不太正规,现在就先用到,下次又做东西时再重构了~~~HOHO~~
posted @ 2006-05-02 22:43  随机  阅读(149)  评论(0)    收藏  举报