Asp.Net实现的通用分页函数

这篇文章主要介绍了Asp.Net实现的通用分页函数,结合实例形势分析了asp.net分页函数的功能,定义及使用技巧,需要的朋友可以参考下

本文实例讲述了Asp.Net实现的通用分页函数。分享给大家供大家参考,具体如下:

功能:

1.每页设置显示9页,超过9页,点5页后的+1页显示(可以随便修改)
2.CSS样式自己可以设置
3.无任何咋代码产生,利于搜索引擎优化

分页程序

objPDS = new PagedDataSource(); objPDS.DataSource = dtTable.DefaultView;//绑定数据源 objPDS.AllowPaging = true; objPDS.PageSize =10;//分页数目 int curPage; int cshi; int jshi; int zyes = Int32.Parse( objPDS.PageCount.ToString()); this.tjixx.Text = "总共 <font color=red>" + dtTable.Rows.Count + " </font>条信息"; this.tjixx.Text += "|共 <font color=red>" + zyes + " </font>页"; if (Request.QueryString["Page"] != null) { if (Int32.Parse(Request.QueryString["Page"]) > zyes) curPage = zyes; else curPage = Int32.Parse(Request.QueryString["Page"]); } else { curPage = 1; } if (zyes <= 9) { cshi = 1; jshi = zyes; } else { if (curPage <= 5) { cshi = 1; jshi = 9; } else { cshi = curPage - 4; int jshils = curPage + 4; if (jshils > zyes) jshi = zyes; else jshi=curPage + 4; } } objPDS.CurrentPageIndex = curPage - 1; StringBuilder m_strPageInfo = new StringBuilder(); for (int i = cshi; i <=jshi; i++) { if (i == Int32.Parse(curPage.ToString())) m_strPageInfo.Append(" <span class=https://www.jb51.net/article/\"dqye\"> <strong>" + i + " </strong> </span> "); else m_strPageInfo.Append(" <span class=https://www.jb51.net/article/\"qtye\"> <strong> <a href=https://www.jb51.net/article/\"newslist_ej" + Request.QueryString["wzcat"] + "_Page" + i + ".html\">" + i + " </a> </strong> </span> "); } this.yemsl.Text = m_strPageInfo.ToString(); if (!objPDS.IsFirstPage) { linkPre.NavigateUrl = "newslist_ej" + Request.QueryString["wzcat"] + "_Page" + Convert.ToString(curPage - 1); linkPre.NavigateUrl += ".html"; } if (!objPDS.IsLastPage) { linkNext.NavigateUrl = "newslist_ej" + Request.QueryString["wzcat"] + "_Page" + Convert.ToString(curPage + 1); linkNext.NavigateUrl += ".html"; } linkFirstPage.NavigateUrl = "newslist_ej" + Request.QueryString["wzcat"] + "_Page1"; linkFirstPage.NavigateUrl += ".html"; linkEndPage.NavigateUrl = "newslist_ej" + Request.QueryString["wzcat"] + "_Page" + objPDS.PageCount.ToString(); linkEndPage.NavigateUrl += ".html"; this.DataList4.DataSource = objPDS;//绑定分页的数据 this.DataList4.DataBind();

Aspx文件:

分页部分:

<div> <asp:HyperLink runat="server" Font-Underline="False">首页 </asp:HyperLink>&lt;&lt; <asp:HyperLink runat="server" Font-Underline="False">上一页 </asp:HyperLink> <asp:Literal runat="server"> </asp:Literal> <asp:HyperLink runat="server" Font-Underline="False">下一页 </asp:HyperLink>&nbsp; &nbsp; &gt;&gt; <asp:HyperLink runat="server" Font-Underline="False">尾页 </asp:HyperLink>| <asp:Literal runat="server"> </asp:Literal> </div>

更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。

希望本文所述对大家asp.net程序设计有所帮助。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwzwx.html