1 public class PageString 2 { 3 /// <summary> 4 /// 5 /// </summary> 6 /// <param name="pageSize">一页多少条</param> 7 /// <param name="currentPage">当前页</param> 8 /// <param name="totalCount">总条数</param> 9 /// <returns></returns> 10 public static string ShowPageNavigate(int pageSize, int currentPage, int totalCount) 11 { 12 string redirectTo = ""; 13 pageSize = pageSize == 0 ? 3 : pageSize; 14 var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数 15 var output = new StringBuilder(); 16 if (totalPages > 1) 17 { 18 if (currentPage != 1) 19 {//处理首页连接 20 output.AppendFormat("<a class='pageLink' href='{0}?pageIndex=1&pageSize={1}'>首页</a> ", redirectTo, pageSize); 21 } 22 if (currentPage > 1) 23 {//处理上一页的连接 24 output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>上一页</a> ", redirectTo, currentPage - 1, pageSize); 25 } 26 else 27 { 28 // output.Append("<span class='pageLink'>上一页</span>"); 29 } 30 31 output.Append(" "); 32 int currint = 5; 33 for (int i = 0; i <= 10; i++) 34 {//一共最多显示10个页码,前面5个,后面5个 35 if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages) 36 { 37 if (currint == i) 38 {//当前页处理 39 //output.Append(string.Format("[{0}]", currentPage)); 40 output.AppendFormat("<a class='cpb' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage, pageSize, currentPage); 41 } 42 else 43 {//一般页处理 44 output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint); 45 } 46 } 47 output.Append(" "); 48 } 49 if (currentPage < totalPages) 50 {//处理下一页的链接 51 output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>下一页</a> ", redirectTo, currentPage + 1, pageSize); 52 } 53 else 54 { 55 //output.Append("<span class='pageLink'>下一页</span>"); 56 } 57 output.Append(" "); 58 if (currentPage != totalPages) 59 { 60 output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>末页</a> ", redirectTo, totalPages, pageSize); 61 } 62 output.Append(" "); 63 } 64 output.AppendFormat("第{0}页 / 共{1}页", currentPage, totalPages);//这个统计加不加都行 65 return output.ToString(); 66 } 67 68 }