0. 没有找到一款中意的分页插件,又不想使用现成的(丑到爆),所以自己动手造一个吧
先看下效果(其实也不咋滴...):
我的小站地址:我的Bootstrap小站;
PS:(问博客园:为什么老是删我的置顶随便?上一篇阅读量都快500了,也分分钟给我从首页删掉...真是无语了<博客园地址:http://www.cnblogs.com/haust/p/5615946.html> )。
有点另类,分页直接是在后台拼接好html,然后发送到前台的:
1. 分页容器:
<div class="pagination"> <ul> //************分页HTML********* </ul> </div>
2. PagerHelper:
namespace ZYN.BLOG.WebHelper { public class PagerHelper { /// <summary> /// 生成分页Html数据 /// </summary> /// <param name="currentPage">当前页</param> /// <param name="pageSize">页容量</param> /// <param name="totalCount">数据总条数</param> /// <returns>pagerHtmlString</returns> public static string GeneratePagerString(int currentPage, int pageSize, int totalCount) { var redirectToUrl = HttpContext.Current.Request.Url.AbsolutePath; pageSize = pageSize <= 0 "<li id='start-page'><a href='{0}", redirectToUrl, 1, pageSize); //处理上一页:如果当前页不是第一页,就加上上一页 if (currentPage > 1) { pagerHtmlString.AppendFormat("<li class='prev-page'><a href='{0}", redirectToUrl, currentPage - 1, pageSize); } //假如起始位置start为1 7 13 for (int i = 0; i < curBarCapacity; i++) //curBarCapacity=3 i=0 1 2 { int j = start + i; //要显示的页码当量值 if (j == currentPage) { //对当前页的处理:class=active pagerHtmlString.AppendFormat("<li class='active show-page'><span>{0}</span></li> ", currentPage); if (curBarCapacity == pageBarSize) { //不处理最后一个分页条页 if (currentPage == start + pageBarSize - 1) { if (currentPage + 1 < totalPages) { endHtmlString.AppendFormat("<li class='show-page'><a href='{0}", redirectToUrl, currentPage + 1, pageSize, currentPage + 1); } endHtmlString.Append("<li class='show-page'><span>...</span></li>"); endHtmlString.AppendFormat("<li class='show-page'><a href='{0}", redirectToUrl, totalPages, pageSize, totalPages); } } } else { pagerHtmlString.AppendFormat("<li class='show-page'><a href='{0}", redirectToUrl, j, pageSize, j); } } //省略号的处理 pagerHtmlString.Append(endHtmlString.ToString()); //处理下一页:如果当前页不是最后一页,则加上下一页。也即中间的所有分页条都显示下一页 if (currentPage != totalPages) { pagerHtmlString.AppendFormat("<li class='next-page'><a href='{0}", redirectToUrl, currentPage + 1, pageSize); } //处理末页 pagerHtmlString.AppendFormat("<li id='end-page'><a href='{0}", redirectToUrl, totalPages, pageSize); pagerHtmlString.AppendFormat("<li id='total-page'><span>共-{0}-页</span></li>", totalPages); pagerHtmlString.Append(" "); return pagerHtmlString.ToString(); } } }
3 渲染出来的分页HTML是这样的:
<div class="pagination"> <ul> <li id="start-page"><a href="/Home/WrapArtList/0">首页</a></li> <li class="active show-page"><span>1</span></li> <li class="show-page"><a href="/Home/WrapArtList/0">2</a></li> <li class="show-page"><a href="/Home/WrapArtList/0">3</a></li> <li class="show-page"><a href="/Home/WrapArtList/0">4</a></li> <li class="show-page"><a href="/Home/WrapArtList/0">5</a></li> <li class="next-page"><a href="/Home/WrapArtList/0">下一页</a></li> <li id="end-page"><a href="/Home/WrapArtList/0">末页</a></li> <li id="total-page"><span>共-5-页</span></li> </ul> </div>
4. CSS样式:
/* 分页样式pagination ====== */ .pagination { /* div pagination*/ margin: 0; padding: 20px; text-align: center; font-size: 12px; display: block; } .pagination ul { display: inline-block; *display: inline; *zoom: 1; margin-left: 0; margin-bottom: 0; padding: 0; } .pagination ul > li { display: inline; } .pagination ul > li > a, .pagination ul > li > span { margin: 0 2px; float: left; padding: 5px 12px; background-color: #ddd; color: #666; border-radius: 2px; opacity: .88; } .pagination ul > li > a:hover, .pagination ul > li > a:focus { background-color: #bce8f1; } .pagination ul > .active > a, .pagination ul > .active > span { background-color: #45B6F7; color: #fff; } .pagination ul > .active > a, .pagination ul > .active > span { cursor: default; } .pagination ul > li > span, .pagination ul > .disabled > span, .pagination ul > .disabled > a, .pagination ul > .disabled > a:hover, .pagination ul > .disabled > a:focus { color: #999999; background-color: transparent; cursor: default; } /* 自定义的分页pagination 结束====== */
以上所述是小编给大家介绍的利用ASP.NET MVC+Bootstrap搭建个人博客之打造清新分页Helper(三),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“利用ASP.NET MVC+Bootstrap搭建个人博客之打造清新分页Helper(三)”评论...