本文實(shí)例講述了Asp.Net實(shí)現(xiàn)的通用分頁(yè)函數(shù)。分享給大家供大家參考,具體如下:
功能:
1.每頁(yè)設(shè)置顯示9頁(yè),超過9頁(yè),點(diǎn)5頁(yè)后的+1頁(yè)顯示(可以隨便修改)
2.CSS樣式自己可以設(shè)置
3.無任何咋代碼產(chǎn)生,利于搜索引擎優(yōu)化
分頁(yè)程序
objPDS = new PagedDataSource();
objPDS.DataSource = dtTable.DefaultView;//綁定數(shù)據(jù)源
objPDS.AllowPaging = true;
objPDS.PageSize =10;//分頁(yè)數(shù)目
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>頁(yè)";
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;//綁定分頁(yè)的數(shù)據(jù)
this.DataList4.DataBind();
Aspx文件:
分頁(yè)部分:
div align="center"> asp:HyperLink ID="linkFirstPage" runat="server" Font-Underline="False">首頁(yè) /asp:HyperLink>lt;lt;
asp:HyperLink ID="linkPre" runat="server" Font-Underline="False">上一頁(yè) /asp:HyperLink>
asp:Literal ID="yemsl" runat="server"> /asp:Literal>
asp:HyperLink ID="linkNext" runat="server" Font-Underline="False">下一頁(yè) /asp:HyperLink>nbsp; nbsp;
gt;gt; asp:HyperLink
ID="linkEndPage" runat="server" Font-Underline="False">尾頁(yè) /asp:HyperLink>| asp:Literal
ID="tjixx" runat="server"> /asp:Literal> /div>
更多關(guān)于asp.net相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《asp.net文件操作技巧匯總》、《asp.net ajax技巧總結(jié)專題》及《asp.net緩存操作技巧總結(jié)》。
希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- ASP.NET和MSSQL高性能分頁(yè)實(shí)例代碼
- asp.net+ajax簡(jiǎn)單分頁(yè)實(shí)例分析
- asp.net分頁(yè)功能實(shí)現(xiàn)
- ASP.NET無刷新分頁(yè)簡(jiǎn)單實(shí)現(xiàn)
- asp.net實(shí)現(xiàn)簡(jiǎn)單分頁(yè)實(shí)例
- asp.net gridview分頁(yè):第一頁(yè) 下一頁(yè) 1 2 3 4 上一頁(yè) 最末頁(yè)
- asp.net使用AJAX實(shí)現(xiàn)無刷新分頁(yè)
- asp.net中的GridView分頁(yè)問題
- ASP.NET MVC 5使用X.PagedList.Mvc進(jìn)行分頁(yè)教程(PagedList.Mvc)
- asp.net利用后臺(tái)實(shí)現(xiàn)直接生成html分頁(yè)的方法
- asp.net 使用js分頁(yè)實(shí)現(xiàn)異步加載數(shù)據(jù)
- asp.net中利用Jquery+Ajax+Json實(shí)現(xiàn)無刷新分頁(yè)的實(shí)例代碼