HTML动态分页函数

HTML动态分页函数

public class PageBarHelper{
        /// 
        /// 动态分页函数
        /// 
        /// 总页数
        /// 当前页码
        /// 
        public static string GetpageBar(int pageIndex, int pagecount)
        {
            if (pagecount == 1)
            {
                return string.Empty;
            }
            int start = pageIndex - 5;
            if (start < 1)
            {
                start = 1;
            }
            int end = start + 9;
            if (end > pagecount)
            {
                end = pagecount;
                start = end - 9 < 1 ? 1 : end - 9;

            }
            StringBuilder sb = new StringBuilder();
            if (pageIndex > 1)
            {

                sb.AppendFormat("上一页 ", pageIndex - 1);
            }
            for (int i = start; i <= end; i++)
            {
                if (i == pageIndex)
                {
                    sb.Append(i);
                }
                else
                {
                    sb.AppendFormat("{0} ", i);
                   
                }
            }
            if (pageIndex < pagecount)
            {

                sb.AppendFormat("下一页    ", pageIndex + 1);
            }
            return sb.ToString();
        }
}

myPageBar样式参考

 .myPageBar {
            border: solid 1px #d6d6d6;
            border-radius: 0.2rem;
            color: #7d7d7d;
            text-decoration: none;
            text-transform: uppercase;
            display: inline-block;
            text-align: center;
            padding: 0.18rem 0.36rem;
        }

案例应用:

  @MvcHtmlString.Create(PageBarHelper.GetpageBar((int)ViewData["pageIndex"], (int)ViewData["pagecount"]))
 
第  页  

 共 @ViewData["pagecount"] 页

注:来自某IT培训班,可添加参数,动态筛选后分页效果

你可能感兴趣的:(HTML)