散分:分享一个通用分页函数
功能:
1.每页设置显示9页,超过9页,点5页后的+1页显示(可以随便修改)
2.CSS样式自己可以设置
3.无任何咋代码产生,利于搜索引擎优化
4.至于性能怎么样大家可以试下
演示地址:http://www.dzswej.com/newslist_ej4.html
PagedDataSource objPDS;
......
//分页程序
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;//绑定分页的数据