Function:
1. Each page is set to display 9 pages, more than 9 pages, + 1 page after 5 pages (can be modified as needed)
2. Set CSS styles by yourself
3. Nothing
Code Generation, facilitating Search Engine Optimization
// Pagination Program
Objpds = new pageddatasource ();
Objpds. datasource = dttable. defaultview; // bind a data source
Objpds. allowpaging = true;
Objpds. pagesize = 10; // Number of pages
Int curpage;
Int cshi;
Int jshi;
Int zyes = int32.parse (objtp.pagecount. tostring ());
This. tjixx. Text = "Total <font color = Red>" + dttable. Rows. Count + "</font> information ";
This. tjixx. Text + = "| Total <font color = Red>" + zyes + "</font> pages ";
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 (! Objpps. isfirstpage)
{
Linkpre. navigateurl = "newslist_ej" + request. querystring ["wzcat"] + "_ page" + convert. tostring (curpage-1 );
Linkpre. navigateurl + = ". html ";
}
If (! Objpps. 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" + objpd.pagecount. tostring ();
Linkendpage. navigateurl + = ". html ";
This. datalist4.datasource = objpds; // bind the paging data.
This. datalist4.databind ();
// Aspx file:
Paging part:
<Div align = "center"> <asp: hyperlink id = "linkfirstpage" runat = "server" font-underline = "false"> homepage </ASP: hyperlink> & lt; & lt;
<Asp: hyperlink id = "linkpre" runat = "server" font-underline = "false"> previous page </ASP: hyperlink>
<Asp: literal id = "yemsl" runat = "server"> </ASP: literal>
<Asp: hyperlink id = "linknext" runat = "server" font-underline = "false"> next page </ASP: hyperlink> & nbsp;
& Gt; <asp: hyperlink
Id = "linkendpage" runat = "server" font-underline = "false"> last page </ASP: hyperlink> | <asp: literal
Id = "tjixx" runat = "server"> </ASP: literal> </div>