Asp.net url paging code

Source: Internet
Author: User

Copy codeThe 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:
Code
Copy 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:
Code
Copy 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 ();

}
Public void ShowPageData (DataTable dt, string url)
{
// Cp. CssUrl = "Style/PageCut.css ";
Id = Request. QueryString ["id"];
Cp. ID = id;
Cp. DT = dt;
Had. InnerHtml = "<link href = \" css/text \ "src = '" + cp. CssUrl + "'/> ";
If (id = null | id = "")
{
Cp. CurretPage = 1;
}
Else
{
Cp. CurretPage = Convert. ToInt32 (id );
}
Cp. Url = url;
Cp. DataCount = 2;
Cp. Count = cp. DT. Rows. Count;
Cp. CutPageMethod (lt );
For (int I = cp. StartID; I <cp. EndID; I ++)
{
LiInfo. Text + = cp. DT. Rows [I] [1]. ToString () + "<br/> ";
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.