Method:
/// <Summary>
/// Document paging Function
/// </Summary>
/// <Param name = "content"> content </param>
/// <Param name = "currentpage"> current page number </param>
/// <Param name = "pageurl"> current page address </param>
Protected string [] articlepage (string content, int currentpage, string pageurl)
{
String [] result = new string [2];
Int pagecount = 0; // Number of pages
Content = content. replace ("<Div style = \" Page-break-after: Always \ "> <span style = \" display: None \ "> & nbsp; </span> </div> "," [-- page --] "); // Replace the default paging character generated by fck in IE with the custom paging character.
String [] tempcontent = system. text. regularexpressions. regEx. split (content, "\ u005b -- page --]"); // obtain the Escape Character "\ u005b" "["
Pagecount = tempcontent. length;
String outputcontent = ""; // content to be output
If (pagecount <= 1)
{
Outputcontent = content; // document content
Result [0] = string. empty;
}
Else
{
String pagestr = ""; // pagination string
If (currentpage! = 1)
{
// If no parameter is set, change "& CP =" "? CP ="
Pagestr + = "<a class = 'prev' href =" + pageurl + "& CP =" + (currentpage-1) + "> <previous page </a> ";
}
For (INT I = 1; I <= pagecount; I ++)
{
If (I = currentpage)
Pagestr + = ("<SPAN class = 'active'> [" + I + "] </span> ");
Else
{
// If no parameter is set, change "& CP =" "? CP ="
Pagestr + = ("<a class = 'num' href =" + pageurl + "& CP =" + I + "> [" + I + "] </a>" );
}
}
If (currentpage! = Pagecount)
{
// If no parameter is set, change "& CP =" "? CP ="
Pagestr + = "<a class = 'Next' href =" + pageurl + "& CP =" + (currentpage + 1) + "> next page >></A> ";
}
Result [0] = pagestr;
Outputcontent = tempcontent [currentpage-1]. tostring ();
}
Result [1] = outputcontent;
Return result;
}
// Call
Public partial class jxjl: system. Web. UI. Page
{
Sqlconnection conn = new sqlconnection (sqlhelper. Conn );
Sqlcommand cmd;
Sqldatareader Dr;
String [] REE = new string [2];
Int cpage = 1;
String purl = "";
Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
If (request. querystring ["ID"]! = NULL)
{
// Paging address
Purl = "jxjl. aspx? Id = "+ request. querystring [" ID "] + "";
Sel ();
}
Else
{
// Upload to the error page
// BIND ();
}
}
}
Private void sel ()
{
Try
{
If (conn. State = connectionstate. Closed)
{
Conn. open ();
}
String code = "select title, content from zj_article where id = '" + request. querystring ["ID"]. tostring () + "'";
Cmd = new sqlcommand (Code, Conn );
Cmd. commandtimeout = 200;
Dr = cmd. executereader ();
If (dr. hasrows)
{
While (dr. Read ())
{
If (request. querystring ["CP"]! = NULL)
{
Cpage = convert. toint32 (request. querystring ["CP"]. tostring ());
}
REE = articlepage (Dr ["content"]. tostring (), cpage, purl );
// Display the page number
This. labpage. Text = REE [1]; this. labcontent. Text = REE [0];
}
}
}
Finally
{
If (conn. State = connectionstate. open)
{
// Dr. Close ();
Conn. Close ();
}
}
}
}
}
// Add two labels to the foreground
Labpage (page number) labcontent (content)