Asp.Net实现的通用分页函数
程序员文章站
2023-12-19 08:43:40
本文实例讲述了asp.net实现的通用分页函数。分享给大家供大家参考,具体如下:
功能:
1.每页设置显示9页,超过9页,点5页后的+1页显示(可以随便修改)
2.c...
本文实例讲述了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=\"dqye\"> <strong>" + i + " </strong> </span> "); else m_strpageinfo.append(" <span class=\"qtye\"> <strong> <a href=\"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 align="center"> <asp:hyperlink id="linkfirstpage" runat="server" font-underline="false">首页 </asp:hyperlink><< <asp:hyperlink id="linkpre" runat="server" font-underline="false">上一页 </asp:hyperlink> <asp:literal id="yemsl" runat="server"> </asp:literal> <asp:hyperlink id="linknext" runat="server" font-underline="false">下一页 </asp:hyperlink> >> <asp:hyperlink id="linkendpage" runat="server" font-underline="false">尾页 </asp:hyperlink>| <asp:literal id="tjixx" runat="server"> </asp:literal> </div>
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。