码迷,mamicode.com
首页 > 其他好文 > 详细

分页效果

时间:2014-11-14 09:12:30      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   sp   for   div   on   art   

搞定分页效果,虽然不完善,呵,用着,足够了.from:www.sysoft.cc

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace SysoftSite
{
    public partial class Pager : System.Web.UI.UserControl
    {
        protected string Html;
        private int pagecount;

        public int Pagecount
        {
            get { return pagecount; }
            set { pagecount = value; }
        }
        private int pageindex;

        public int Pageindex
        {
            get { return pageindex; }
            set { pageindex = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (pagecount <= 1)
            {
                Html = "[1]";
                return;
            }
            int start = 0;
            if (pagecount > 10 && pageindex + 4 > pagecount)
            {
                start = pageindex - (10-((pagecount-pageindex)+1));
            }
            else
            {
                start = pageindex - 5;
            }
            if (start < 1)
            {
                start = 1;
            }
            int end = start + 9;
            if (end > pagecount)
            {
                end = pagecount;
            }
            StringBuilder sb = new StringBuilder();
            for (int i = start; i <=end; i++)
            {
                if (i == pageindex)
                {
                    sb.AppendFormat(" [" + i + "] ");
                }
                else
                {
                    sb.AppendFormat(" <a href=?pageindex="+i+">[" + i + "]</a> ");
                }
            }
            Html = sb.ToString();
        }
    }
}

  

分页效果

标签:blog   io   ar   os   sp   for   div   on   art   

原文地址:http://www.cnblogs.com/sysoft/p/4096385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!