分页实现
public interface IGetList<T>{/// <summary>/// 返回一個集合/// </summary>/// <param name="pageindex">當(dāng)前頁</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>(); #endregionstring linkstr = "index.aspx?&pageindex=";#region 產(chǎn)生分頁條碼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 MyRegionsbpager.Append("<a href='"+linkstr + 1 + "'>首頁</a> ");if (pageindex != 1){sbpager.Append("<a href='"+linkstr + (pageindex - 1) + "'>上一頁</a> ");}#endregionif (pagecount <= 10){#region MyRegionfor (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 MyRegionfor (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 MyRegionint 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 MyRegionint 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 MyRegionif (pageindex != pagecount){sbpager.Append("<a href='" + linkstr + (pageindex + 1) + "'>下一頁</a> ");} #endregionsbpager.Append("<a href=" + linkstr + pagecount + ">尾頁</a>");#endregion} View Code
?
轉(zhuǎn)載于:https://www.cnblogs.com/fierceeagle/p/5419246.html
總結(jié)
- 上一篇: spring 动态数据源
- 下一篇: 监听iPhone的通话状态之---Cor