首页 > 代码库 > 自己写了一个分页类

自己写了一个分页类

第一次发文章,格式不太规范,不过以后会逐渐改正的,请大家多多指正

 

?
public class Pager
    {
        private string _pageurl;
        private int _pagecount;
        private int _currentpage;
 
        public Pager(string pageurl, int pagecount, int currentpage)
        {
            this._pageurl = pageurl;
            this._pagecount = pagecount;
            this._currentpage = currentpage;
        }
 
        /// <summary>
        /// 页面地址
        /// </summary>
        public string PageUrl
        {
            get { return _pageurl; }
            set { _pageurl = value; }
        }
        /// <summary>
        /// 分页总数
        /// </summary>
        public int PageCount
        {
            get { return _pagecount; }
            set { _pagecount = value; }
 
        }
        /// <summary>
        /// 当前页
        /// </summary>
        public int CurrentPage
        {
            get { return _currentpage; }
            set { _currentpage = value; }
        }
 
        public string Load()
        {
            StringBuilder sbPager = new StringBuilder();
            sbPager.Append("<table class=‘pager‘>");
            sbPager.Append("<tr style=‘background-color:#eeeeee;‘>");
            if (CurrentPage == 1)
            {
                sbPager.Append("<td>首页</td>");
                sbPager.Append("<td>上一页</td>");
            }
            else
            {
                sbPager.Append("<td><a href=http://www.mamicode.com/‘" + PageUrl + "‘>首页</a></td>");
                sbPager.Append("<td><a href=http://www.mamicode.com/‘" + PageUrl + "&currentpage=" + (CurrentPage - 1) + "‘>上一页</a></td>");
            }
 
            sbPager.Append("<td style=‘width:100px;‘>当前为第" + CurrentPage + "页</td>");
            if (CurrentPage == PageCount || PageCount == 0)
            {
                sbPager.Append("<td>下一页</td>");
                sbPager.Append("<td>尾页</td>");
            }
            else
            {
                sbPager.Append("<td><a href=http://www.mamicode.com/‘" + PageUrl + "&currentpage=" + (CurrentPage + 1) + "‘>下一页</a></td>");
                sbPager.Append("<td><a href=http://www.mamicode.com/‘" + PageUrl + "&currentpage=" + PageCount + "‘>尾页</a></td>");
            }
            sbPager.Append("<td>总页数为" + PageCount + "页</td>");
            sbPager.Append("</tr>");
            sbPager.Append("</table>");
            return sbPager.ToString();
        }
    }

 直接从后台输出到页面上就可以了,如果有多个页面,会以url传参的形式重新加载此当前页面,重新调用QueryString的参数,加载页面的数据.....