• 分页实现


     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
  • 相关阅读:
    各种图示的介绍及绘制(boxplot、stem)
    各种图示的介绍及绘制(boxplot、stem)
    Python Tricks(二十二)—— small tricks
    Python Tricks(二十二)—— small tricks
    matplotlib tricks(关闭坐标刻度、坐标轴不可见)
    matplotlib tricks(关闭坐标刻度、坐标轴不可见)
    图灵机(Turing Machine)
    基于TCP/IP的Matlab Modbus与M340 PLC通讯
    hdu1195 Open the Lock (DFS)
    Java菜鸟学习笔记--数组篇(二):数组实例&args实例
  • 原文地址:https://www.cnblogs.com/fierceeagle/p/5419246.html
Copyright © 2020-2023  润新知