CopyCode The Code is as follows: using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. text;
/// <Summary>
/// Summary of cutpage
/// </Summary>
Public class cutpage
{
Public cutpage ()
{
//
// Todo: add the constructor logic here
//
}
# Region private member variable
Private string URL; // The page address used for paging
Private int count; // The total number of data entries.
Private int pagecount; // the total number of pages.
Private int curretpage; // current page number
Private string ID; // receives the value of the passed parameter.
Private int startid; // The start value of the data loop.
Private int endid; // The end value of the data.
Private datatable DT; // data DT Value
Private int datacount; // actual number of data entries per page
Private string cssurl; // cssurl
# Endregion
# Region Public Variables
/// <Summary>
/// URL
/// </Summary>
Public String URL
{
Get
{
Return URL;
}
Set
{
This. url = value;
}
}
/// <Summary>
/// Total number of data entries
/// </Summary>
Public int count
{
Get
{
Return count;
}
Set
{
This. Count = value;
}
}
/// <Summary>
/// Total number of data pages (This field is read-only)
/// </Summary>
Public int pagecount
{
Get
{
If (count % datacount = 0)
{
Return convert. toint32 (count/datacount );
}
Else
{
Return convert. toint32 (count/datacount) + 1;
}
}
}
/// <Summary>
/// Paginated style table URL
/// </Summary>
Public String cssurl
{
Get {return cssurl ;}
Set {this.css url = value ;}
}
/// <Summary>
/// Current page number
/// </Summary>
Public int curretpage
{
Get {return this. curretpage ;}
Set {This. curretpage = value ;}
}
/// <Summary>
/// Passed parameter value
/// </Summary>
Public String ID
{
Get {return this. ID ;}
Set {This. ID = value ;}
}
/// <Summary>
/// Data start value (This field is read-only)
/// </Summary>
Public int startid
{
Get
{
If (curretpage = 1)
{
Return 0;
}
Else
{
Return (curretPage-1) * datacount;
}
}
}
/// <Summary>
/// Data end value (This field is read-only)
/// </Summary>
Public int endid
{
Get
{
If (curretpage = pagecount)
{
Return this. dt. Rows. count;
}
Else
{
Return (curretpage) * datacount;
}
}
}
/// <Summary>
/// Data source for paging
/// </Summary>
Public datatable dt
{
Get {return this. DT ;}
Set {This. dt = value ;}
}
/// <Summary>
/// Number of data entries displayed on each page
/// </Summary>
Public int datacount
{
Get {return this. datacount ;}
Set {This. datacount = value ;}
}
# Endregion
/// <Summary>
/// Paging method (the process of generating paging code)
/// </Summary>
/// <Param name = "pageinfo"> literal control </param>
Public void cutpagemethod (literal pt)
{
Stringbuilder orderinfosb = new stringbuilder ();
Orderinfosb. append ("<span style = \" width: 1000px \ "> <tr id = \" pagination-Digg \ "> <TH style = \" width: 180px \ "> ");
Orderinfosb. append ("current" + curretpage + "/" + pagecount + "Page total" + Count + "data entries ");
Orderinfosb. append ("</Th> <TH class = \" previous-off \ "style = \" align: right \ "> ");
If (convert. toint32 (this. ID) = 1)
{
Orderinfosb. append ("<a href = '# 'Disabled = 'flase'> homepage </a> ");
}
Else
{
Orderinfosb. append ("<a href = '" + URL + "? Id = 1 '> homepage </a> ");
}
Orderinfosb. append ("</Th> <TH> ");
If (convert. toint32 (this. ID) = 1 | this. ID = NULL | this. ID = string. Empty)
{
Orderinfosb. append ("<a href = '# 'Disabled = 'flase'> previous page </a> ");
}
Else
{
Orderinfosb. append ("<a href = '" + URL + "? Id = "+ convert. tostring (CurretPage-1) +" '> previous page </a> ");
}
If (convert. toint32 (this. ID) <pagecount)
{
Orderinfosb. append ("<a href = '" + URL + "? Id = "+ convert. tostring (curretpage + 1) +" '> next page </a> ");
}
Else
{
Orderinfosb. append ("<a href = '# 'Disabled = 'flase'> next page </a> ");
}
Orderinfosb. append ("</Th> <TH> ");
If (convert. toint32 (this. ID) = pagecount)
{
Orderinfosb. append ("<a href = '# 'Disabled = 'flase'> last page </a> ");
}
Else
{
Orderinfosb. append ("<a href = '" + URL + "? Id = "+ convert. tostring (pagecount) +" '> last page </a> ");
}
Orderinfosb. append ("</Th> </tr> </span> ");
PT. Text = orderinfosb. tostring ();
}
}
You can add styles by yourself. To be honest, there is no technical content.
Front-end code:
CodeCopy codeThe Code is as follows: <% @ page Language = "C #" autoeventwireup = "true" codefile = "cutpagetest. aspx. cs" inherits = "cutpagetest" enableviewstate = "false" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server" id = "had">
<% -- <Link href = "style/base.css" type = "text/CSS"/> -- %>
<Title> No title page </title>
<Style type = "text/CSS">
A
{
Text-Decoration: none;
}
</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: literal id = "liinfo" runat = "server"> </ASP: literal>
<Asp: literal id = "LT" runat = "server"> </ASP: literal>
<A href = "#"
</Div>
</Form>
</Body>
</Html>
Background code:
CodeCopy codeThe Code is as follows: using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Public partial class cutpagetest: system. Web. UI. Page
{
Cutpage CP = new cutpage ();
String ID;
Protected void page_load (Object sender, eventargs E)
{
Showpagedata (dbhelpersql. queryredt ("select * from test", globalconfig. tcclinedbhelper), "cutpagetest. aspx ");
// Response. Write ();
}< br> Public void showpagedata (datatable DT, string URL)
{< br> // CP. cssurl = "style/pagecut.css";
id = request. querystring ["ID"];
CP. id = ID;
CP. dt = DT;
had. innerhtml = " ";
If (ID = NULL | id = "")
{< br> CP. curretpage = 1;
}< br> else
{< br> CP. curretpage = convert. toint32 (ID);
}< br> CP. url = URL;
CP. datacount = 2;
CP. count = CP. DT. rows. count;
CP. cutpagemethod (LT);
for (INT I = CP. startid; I {< br> liinfo. text + = CP. DT. rows [I] [1]. tostring () + "
";
}< BR >}