asp.net url分頁(yè)類(lèi)代碼
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>
///CutPage 的摘要說(shuō)明
/// </summary>
public class CutPage
{
public CutPage()
{
//
//TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
#region 私有成員變量
private string url; //分頁(yè)時(shí)所用到的頁(yè)面地址
private int count; //數(shù)據(jù)總條數(shù)
private int pageCount; //總頁(yè)數(shù)
private int curretPage; //當(dāng)前頁(yè)數(shù)
private string id; //接收傳遞參數(shù)的值
private int startId; //數(shù)據(jù)循環(huán)的開(kāi)始值
private int endId; //數(shù)據(jù)結(jié)束的值
private DataTable dt; //數(shù)據(jù)dt值
private int dataCount; //每頁(yè)現(xiàn)實(shí)的數(shù)據(jù)條數(shù)
private string cssUrl; //cssURL地址
#endregion
#region 公共變量
/// <summary>
/// Url地址
/// </summary>
public string Url
{
get
{
return url;
}
set
{
this.url = value;
}
}
/// <summary>
/// 數(shù)據(jù)總條數(shù)
/// </summary>
public int Count
{
get
{
return count;
}
set
{
this.count = value;
}
}
/// <summary>
/// 數(shù)據(jù)總頁(yè)數(shù)(該字段只讀)
/// </summary>
public int PageCount
{
get
{
if (count % dataCount == 0)
{
return Convert.ToInt32(count / dataCount);
}
else
{
return Convert.ToInt32(count / dataCount) + 1;
}
}
}
/// <summary>
/// 分頁(yè)樣式表url
/// </summary>
public string CssUrl
{
get { return cssUrl; }
set { this.cssUrl = value; }
}
/// <summary>
/// 當(dāng)前頁(yè)數(shù)
/// </summary>
public int CurretPage
{
get { return this.curretPage; }
set { this.curretPage = value; }
}
/// <summary>
/// 傳遞的參數(shù)值
/// </summary>
public string ID
{
get { return this.id; }
set { this.id = value; }
}
/// <summary>
/// 數(shù)據(jù)開(kāi)始值(該字段只讀)
/// </summary>
public int StartID
{
get
{
if (curretPage == 1)
{
return 0;
}
else
{
return (curretPage-1) * dataCount;
}
}
}
/// <summary>
/// 數(shù)據(jù)結(jié)束的值(該字段只讀)
/// </summary>
public int EndID
{
get
{
if (CurretPage == PageCount)
{
return this.DT.Rows.Count;
}
else
{
return (curretPage) * dataCount;
}
}
}
/// <summary>
/// 用于分頁(yè)的數(shù)據(jù)源
/// </summary>
public DataTable DT
{
get { return this.dt; }
set { this.dt = value; }
}
/// <summary>
/// 每頁(yè)顯示的數(shù)據(jù)條數(shù)
/// </summary>
public int DataCount
{
get { return this.dataCount; }
set { this.dataCount = value; }
}
#endregion
/// <summary>
/// 分頁(yè)方法(生成分頁(yè)代碼的過(guò)程)
/// </summary>
/// <param name="PageInfo">Literal控件 </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("當(dāng)前" + CurretPage + "/" + PageCount + "頁(yè) 共" + Count + "條數(shù)據(jù)");
orderInfoSb.Append("</th><th class=\"previous-off\" style=\"align:right\">");
if (Convert.ToInt32(this.ID) == 1)
{
orderInfoSb.Append("<a href='#' disabled='flase'>首頁(yè)</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id=1'>首頁(yè)</a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID )== 1 || this.ID==null || this.ID==string.Empty)
{
orderInfoSb.Append("<a href='#'disabled='flase'>上一頁(yè)</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(CurretPage-1)+"'>上一頁(yè)</a>");
}
if (Convert.ToInt32(this.ID) < PageCount)
{
orderInfoSb.Append("<a href='" + Url + "?id=" +Convert.ToString(CurretPage + 1) + "'>下一頁(yè)</a>");
}
else
{
orderInfoSb.Append("<a href='#'disabled='flase'>下一頁(yè)</a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID) == PageCount)
{
orderInfoSb.Append("<a href='#' disabled='flase'>末頁(yè)</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(PageCount)+"'>末頁(yè)</a>");
}
orderInfoSb.Append("</th></tr></span>");
pt.Text = orderInfoSb.ToString();
}
}
樣式大家可以自己添,老實(shí)說(shuō)沒(méi)什么技術(shù)含量。
前臺(tái)代碼:
代碼
<%@ 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>無(wú)標(biāo)題頁(yè)</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>
后臺(tái)代碼:
代碼
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/>";
}
}
}
相關(guān)文章
.NET?Core利用?AsyncLocal?實(shí)現(xiàn)共享變量的代碼詳解
在Web?應(yīng)用程序中,我們經(jīng)常會(huì)遇到這樣的場(chǎng)景,如用戶(hù)信息,租戶(hù)信息本次的請(qǐng)求過(guò)程中都是固定的,我們希望是這種信息在本次請(qǐng)求內(nèi),一次賦值,到處使用。本文就來(lái)探討一下,如何在.NET?Core?下去利用AsyncLocal?實(shí)現(xiàn)全局共享變量2022-04-04
ASP.NET Core中間件會(huì)話(huà)狀態(tài)讀寫(xiě)及生命周期示例
這篇文章主要為大家介紹了ASP.NET Core中間件會(huì)話(huà)狀態(tài)讀寫(xiě)及生命周期示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04
.NET性能調(diào)優(yōu)之一:ANTS Performance Profiler的使用介紹
本系列文章主要會(huì)介紹一些.NET性能調(diào)優(yōu)的工具、Web性能優(yōu)化的規(guī)則(如YSlow)及方法等等內(nèi)容。成文前最不希望看到的就是園子里不間斷的“哪個(gè)語(yǔ)言好,哪個(gè)語(yǔ)言性能高”的爭(zhēng)論,不多說(shuō),真正的明白人都應(yīng)該知道這樣的爭(zhēng)論有沒(méi)有意義,希望我們能從實(shí)際性能優(yōu)化的角度去討論問(wèn)題2013-01-01
.NET性能優(yōu)化ValueStringBuilder拼接字符串使用實(shí)例
這篇文章主要為大家介紹了.NET性能優(yōu)化ValueStringBuilder拼接字符串的使用實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
C#中實(shí)現(xiàn)偽靜態(tài)頁(yè)面兩種方式介紹
偽靜態(tài)技術(shù)的誕生,帶動(dòng)了于搜索引擎友好C#中實(shí)現(xiàn)偽靜態(tài)頁(yè)面有兩種方式,本文將一一詳解,感興趣的朋友可以參考下,希望本文對(duì)你學(xué)習(xí)偽靜態(tài)有所幫助2013-01-01
在ASP.Net?Core應(yīng)用程序中使用Bootstrap4
這篇文章介紹了在ASP.Net?Core應(yīng)用程序中使用Bootstrap4的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01
異步 HttpContext.Current實(shí)現(xiàn)取值的方法(解決異步Application,Session,Cache.
在一個(gè)項(xiàng)目中,為了系統(tǒng)執(zhí)行效率更快,把一個(gè)經(jīng)常用到的數(shù)據(jù)庫(kù)表通過(guò)dataset放到Application中,發(fā)現(xiàn)在異步實(shí)現(xiàn)中每一次都會(huì)出現(xiàn)HttpContext.Current為null的異常,后來(lái)在網(wǎng)上查了好多資料,發(fā)現(xiàn)問(wèn)這個(gè)問(wèn)題的人多,回答的少2009-07-07
HTTP 錯(cuò)誤 500.19 - Internal Server Error解決辦法詳解
這篇文章主要介紹了HTTP 錯(cuò)誤 500.19 - Internal Server Error解決辦法詳解的相關(guān)資料,這里對(duì)錯(cuò)誤進(jìn)行了詳細(xì)分析及說(shuō)明該如何解決,需要的朋友可以參考下2016-11-11
Asp.net使用SignalR實(shí)現(xiàn)聊天室的功能
這篇文章主要介紹了Asp.net使用SignalR實(shí)現(xiàn)聊天室的功能的相關(guān)資料,需要的朋友可以參考下2016-04-04

