asp.net URL Pagination Class Code _ Practical Tips

Source: Internet
Author: User
Tags prev
Copy Code code 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 description of Cutpage
</summary>
public class Cutpage
{
Public Cutpage ()
{
//
TODO: Add constructor logic here
//
}
#region Private Member variable
private string URL; Page address used when paging
private int count; Total number of data bars
private int PageCount; Total pages
private int curretpage; Current page
private string ID; Receive the value of the pass parameter
private int startid; Start value of data loop
private int endid; The value of the end of the data
Private DataTable DT; Data DT Value
private int datacount; The number of actual data bars per page
private string Cssurl; Cssurl Address
#endregion
#region Public variables
<summary>
URL address
</summary>
public string Url
{
Get
{
return URL;
}
Set
{
This.url = value;
}
}
<summary>
Total number of data bars
</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>
Page-style sheet URL
</summary>
public string Cssurl
{
get {return cssurl;}
set {This.cssurl = value;}
}
<summary>
Current page
</summary>
public int Curretpage
{
get {return this.curretpage;}
set {this.curretpage = value;}
}
<summary>
The parameter value passed
</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>
The value at which the data ends (the 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>
The number of data bars displayed per page
</summary>
public int Datacount
{
get {return this.datacount;}
set {This.datacount = value;}
}
#endregion
<summary>
Pagination method (process of the raw page code)
</summary>
<param name= "PageInfo" >literal controls </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 + "piece data");
Orderinfosb.append ("</th><th class=\" previous-off\ "style=\" align:right\ ">");
if (Convert.ToInt32 (this.id) = = 1)
{
Orderinfosb.append ("<a href= ' # ' disabled= ' flase ' > Home </a>");
}
Else
{
Orderinfosb.append ("<a href=" + Url + "? id=1 ' > Home </a>");
}
Orderinfosb.append ("</th><th>");
if (Convert.ToInt32 (this.id) = = 1 | | this.id==null | | this.id==string. Empty)
{
Orderinfosb.append ("<a href= ' # ' disabled= ' flase ' > Prev </a>");
}
Else
{
Orderinfosb.append ("<a href=" + Url + "? id=" +convert.tostring (CurretPage-1) + "' > Prev </a>");
}
if (Convert.ToInt32 (this.id) < PageCount)
{
Orderinfosb.append ("<a href=" + Url + "? id=" +convert.tostring (Curretpage + 1) + "' > Next </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 </a>");
}
Else
{
Orderinfosb.append ("<a href=" + Url + "? id=" +convert.tostring (PageCount) + "' > Last </a>");

}
Orderinfosb.append ("</th></tr></span>");
Pt. Text = Orderinfosb.tostring ();

}
}

Style Everyone can add their own, frankly no technical content.
Foreground code:
Code
Copy Code code 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 ">

<%--<link href= "Style/base.css" type= "Text/css"/>--%>

<title> Untitled Page </title>
<style type= "Text/css" >
A
{
Text-decoration:none;

}
</style>
<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>

Background code:
Code
Copy Code code 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.