• 分页实现


     public interface IGetList<T>
        {
            /// <summary>
            /// 返回一个集合
            /// </summary>
            /// <param name="pageindex">当前页</param>
            /// <param name="pagenumber">每页显示多少条</param>
            /// <param name="totle">总共多少条</param>
            /// <param name="dic">查询条件以字典放入</param>
            /// <returns></returns>
            List<T> GetList(int pageindex,int pagenumber,out int totle,Dictionary<string,string> dic);
        }
    View Code
     protected int totle = 0;
            protected int pageindex = 1;
            protected int pagenumber = 20;
            protected double pagecount = 1;
            protected System.Text.StringBuilder sbpager = new System.Text.StringBuilder();
            protected List<People> lis = new List<People>();
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
                InintPager();
              
    
            }
    
    
            /// <summary>
            /// 初始化分页条码
            /// </summary>
            protected void InintPager()
            {
                #region 查询条件
                Dictionary<string, string> dic = new Dictionary<string, string>(); 
                #endregion
    
                string linkstr = "index.aspx?&pageindex=";
    
                #region 产生分页条码
                int totle = 0;
    
                int pageindex = 1;
    
                if (!int.TryParse(Request["pageindex"], out pageindex))
                {
    
                    pageindex = 1;
    
                }
                int pagenumber = 20;
    
                IGetList<People> bll = new Pagerok.BLL();
    
                lis = bll.GetList(pageindex, pagenumber, out  totle,dic);
    
                pagecount = Math.Ceiling(totle * 1.0 / pagenumber);
    
                sbpager.Append(" <a href='#'>共" + pagecount + "页</a>");
    
                #region MyRegion
                sbpager.Append("<a href='"+linkstr + 1 + "'>首页</a> ");
    
    
                if (pageindex != 1)
                {
                    sbpager.Append("<a href='"+linkstr + (pageindex - 1) + "'>上一页</a> ");
                }
                
                #endregion
    
    
                if (pagecount <= 10)
                {
    
                    #region MyRegion
                    for (int i = 0; i < pagecount; i++)
                    {
                        if ((i + 1) == pageindex)
                        {
                            sbpager.Append("<a class='current' href='#'>" + (i + 1) + " </a>");
                        }
                        else
                        {
                            sbpager.Append("<a href='"+linkstr + (i + 1) + "'>" + (i + 1) + " </a>");
                        }
    
                    }
                    #endregion
    
                }
                else if (pageindex < 5)
                {
    
                    #region MyRegion
                    for (int i = 0; i < 10; i++)
                    {
                        if ((i + 1) == pageindex)
                        {
                            sbpager.Append("<a class='current' href='#'>" + (i + 1) + " </a>");
                        }
                        else
                        {
                            sbpager.Append("<a href='" + linkstr + (i + 1) + "'>" + (i + 1) + " </a>");
                        }
    
                    }
                    #endregion
    
                }
                else if (pageindex > pagecount - 5)
                {
    
                    #region MyRegion
                    int t = int.Parse(pagecount.ToString()) - 10;
    
                    for (int i = t; i < pagecount; i++)
                    {
                        if ((i + 1) == pageindex)
                        {
                            sbpager.Append("<a class='current' href='#'>" + (i + 1) + " </a>");
                        }
                        else
                        {
                            sbpager.Append("<a href='" + linkstr + (i + 1) + "'>" + (i + 1) + " </a>");
                        }
                    } 
                    #endregion
                }
                else
                {
    
                    #region MyRegion
                    int t1 = pageindex - 5;
                    int t2 = pageindex + 4;
    
                    for (int i = t1; i < t2; i++)
                    {
                        if ((i + 1) == pageindex)
                        {
                            sbpager.Append("<a class='current' href='#'>" + (i + 1) + " </a>");
                        }
                        else
                        {
                            sbpager.Append("<a href='" + linkstr + (i + 1) + "'>" + (i + 1) + " </a>");
                        }
                    } 
                    #endregion
    
                }
    
    
                #region MyRegion
                if (pageindex != pagecount)
                {
                    sbpager.Append("<a href='" + linkstr + (pageindex + 1) + "'>下一页</a> ");
                } 
                #endregion
    
    
                sbpager.Append("<a href=" + linkstr + pagecount + ">尾页</a>");
                #endregion
            
            }
    View Code
  • 相关阅读:
    VS2010、SQL Server 2008和SQL Server 2012安装详解
    IIS服务寄宿
    C#中错误:不包含适合于入 口点的静态“Main”方法 的解决方法
    硬件的一些性能指标
    SATA SAS SSD 硬盘介绍和评测
    mysql数据库锁定机制
    mysql日志设置优化
    MySQL硬件瓶颈分析
    可扩展性设计之数据切分
    硬件环境对系统性能的影响
  • 原文地址:https://www.cnblogs.com/fierceeagle/p/5419246.html
Copyright © 2020-2023  润新知