生成分页按钮的方法

翻页按钮的样式表

.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a 
{padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px; color:#ff6400}
.paginator a:visited 
{padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb 
{color: #fff; background: #ff6400 ;border-color:#fff;text-decoration: none;padding: 1px 6px; border: solid 1px #ffb17f;}
.paginator a:hover 
{color: #fff; background: #ff6400;border-color:#ffb17f;text-decoration: none;}

 

 生成分页按钮的方法

    #region 静态方法:生成分页按钮的方法    
    
/// <summary>
    
/// 静态方法:生成分页按钮的方法
    
/// </summary>
    
/// <param name="_Url">链接地址</param>
    
/// <param name="_RecordCount">记录总数</param>
    
/// <param name="_PageSize">每页记录条数</param>
    
/// <param name="_CurrentPage">当前页</param>
    
/// <returns></returns>
    public static string PageButton(string _Url,int _RecordCount,int _PageSize,int _CurrentPage)
    {
        
int PageTol = _RecordCount % _PageSize > 0 ? _RecordCount / _PageSize + 1 : _RecordCount / _PageSize;
        
string Return = "<div  class=\"paginator\">";
        
if (_CurrentPage < 1) { _CurrentPage = 1; }
        Return 
+= _CurrentPage == 1 ? "<a disabled=\"disabled\" style=\"margin-right: 5px;\">首页</a>" : "<a class=\"paginator\" href=\"" +string.Format(  _Url,"1") + "\" style=\"margin-right: 5px;\">首页</a>";
        Return 
+= _CurrentPage > 1 ? "<a class=\"paginator\" href=\"" + string.Format( _Url, (_CurrentPage-1).ToString())+ "\" style=\"margin-right: 5px;\">上一页</a>" : "<a disabled=\"disabled\" style=\"margin-right: 5px;\">上一页</a>";
        
int StartBut = _CurrentPage - 5;       //////一共显示10个按钮
        if (StartBut < 1) { StartBut = 1; }
        
int EndBut = _CurrentPage +5;
        
if (EndBut > PageTol) { EndBut = PageTol; }
        
if (StartBut > 1) { Return += "<a href=\"" + string.Format(_Url, (StartBut - 1).ToString()) + "\" class=\"paginator\" style=\"margin-right: 5px;\">···</a>"; }
        
for (int i=StartBut ; i <EndBut +1; i++)
        {
            Return 
+= i == _CurrentPage ? "<span class=\"cpb\" style=\"margin-right: 5px;\">" + i.ToString() + "</span>" : "<a href=\"" + string.Format(_Url, i.ToString()) + "\" class=\"paginator\" style=\"margin-right: 5px;\">" + i.ToString() + "</a>";
        }
        
if (EndBut < PageTol) { Return += "<a href=\"" + string.Format(_Url, (EndBut+1).ToString()) + "\" class=\"paginator\" style=\"margin-right: 5px;\">···</a>"; }
        Return 
+= _CurrentPage < PageTol ? "<a class=\"paginator\" href=\"" + string.Format(_Url, (_CurrentPage + 1).ToString()) + "\" style=\"margin-right: 5px;\">下一页</a>" : "<a disabled=\"disabled\" style=\"margin-right: 5px;\">下一页</a>";
        Return 
+= _CurrentPage == PageTol ? "<a disabled=\"disabled\" style=\"margin-right: 5px;\">尾页</a>" : "<a class=\"paginator\" href=\"" + string.Format(_Url, PageTol.ToString()) + "\" style=\"margin-right: 5px;\">尾页</a>";
        
return Return+"</div>";
    }

    #endregion

posted on 2009-05-13 17:32  郑州--飞猫  阅读(461)  评论(2编辑  收藏  举报

导航