首页 > 代码库 > 分页效果

分页效果

搞定分页效果,虽然不完善,呵,用着,足够了.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=http://www.mamicode.com/?pageindex="+i+">[" + i + "]</a> ");                }            }            Html = sb.ToString();        }    }}

  

分页效果