标签:
1 /// <summary> 2 /// 获取数字页面条 3 /// </summary> 4 /// <param name="pageIndex"></param> 5 /// <param name="pageSize"></param> 6 /// <returns></returns> 7 public string GetPageBar(int pageIndex,int pageCount) 8 { 9 if (pageCount==1)//当只有一页的时候 10 { 11 return string.Empty; 12 } 13 //只要把开始页码和结束的页码计算出来的时候就可以遍历输出 14 int start = 0; 15 int end = 0; 16 if (pageCount<=10) 17 { 18 start = 1; 19 end = pageCount; 20 } 21 else 22 { 23 if (pageIndex-5<=0) 24 { 25 start = 1; 26 end = 10; 27 } 28 else 29 { 30 end = pageIndex + 4; 31 if (end>pageCount) 32 { 33 end = pageCount; 34 } 35 start = end - 9; 36 } 37 38 } 39 40 StringBuilder sb = new StringBuilder(); 41 for (int i = start; i <= end; i++) 42 { 43 if (i==pageIndex) 44 { 45 sb.Append(i); 46 } 47 else 48 { 49 sb.AppendFormat("<a href=‘NewList.aspx?pageIndex={0}‘>{0}</a>",i); 50 } 51 } 52 return sb.ToString();
标签:
原文地址:http://www.cnblogs.com/clcloveHuahua/p/5164184.html