PageBarHelper

 public class PageBarHelper
    {
        public static string GetPageBar(int pageIndex, int pageCount)
        {
            if (pageCount == 1) return string.Empty;
            int startPage = pageIndex - 5;
            startPage = startPage < 1 ? 1 : startPage;
            int endPage = startPage + 9;
            if (endPage > pageCount)
            {
                endPage = pageCount;
                startPage = endPage - 9 < 1 ? 1 : endPage - 9;
            }
            StringBuilder sb = new StringBuilder();
            if (pageIndex!=1)
            {
                sb.AppendFormat("<a href=‘/UserInfo/Index?pageIndex={0}‘>首页</a>", 1);
            }
            if (pageIndex > 1)
            {
                sb.AppendFormat("<a href=‘/UserInfo/Index?pageIndex={0}‘>上一页</a>", pageIndex - 1);
            }
            for (int i = startPage; i <= endPage; i++)
            {
                if (i == pageIndex)
                {
                    sb.Append(i);
                }
                else
                {
                    sb.AppendFormat("<a href=‘/UserInfo/Index?pageIndex={0}‘>{0}</a>", i);
                }
            }
            if (pageIndex < pageCount)
            {
                sb.AppendFormat("<a href=‘/UserInfo/Index?pageIndex={0}‘>下一页</a>", pageIndex + 1);
            }
            if (pageIndex != pageCount)
            {
                sb.AppendFormat("<a href=‘/UserInfo/Index?pageIndex={0}‘>尾页</a>", pageCount);
            }
            return sb.ToString();
        }
    }

  

时间: 2024-10-13 03:03:45

PageBarHelper的相关文章

步步为营-78-新闻展示(Ajax+Json+easyUI)

Json:JavaScript Object Notation 1.1 Json对象的接收处理 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title><

分页公共类

PageBarHelper using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CZBK.ItcastProject.Common { public class PageBarHelper { public static string GetPageaBar(int pageIndex, int p

步步为营-73-asp.net的简单练习(根据美工提供静态页面,编写后台代码)

说明:实际企业中开发分工是很明确,往往程序员根据美工提供的UI界面进行后台代码的编写. 1.1 原始HTML页面 1.2 使用aspx进行修改 这里使用到了三层架构 using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; namesp