asp.net url分页类代码

复制代码 代码如下:
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 的摘要说明
/// </summary>
public class CutPage
{
public CutPage()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region 私有成员变量
private string url; //分页时所用到的页面地址
private int count; //数据总条数
private int pageCount; //总页数
private int curretPage; //当前页数
private string id; //接收传递参数的值
private int startId; //数据循环的开始值
private int endId; //数据结束的值
private DataTable dt; //数据dt值
private int dataCount; //每页现实的数据条数
private string cssUrl; //cssURL地址
#endregion
#region 公共变量
/// <summary>
/// Url地址
/// </summary>
public string Url
{
get
{
return url;
}
set
{
this.url = value;
}
}
/// <summary>
/// 数据总条数
/// </summary>
public int Count
{
get
{
return count;
}
set
{
this.count = value;
}
}
/// <summary>
/// 数据总页数(该字段只读)
/// </summary>
public int PageCount
{
get
{
if (count % dataCount == 0)
{
return Convert.ToInt32(count / dataCount);
}
else
{
return Convert.ToInt32(count / dataCount) + 1;
}
}
}
/// <summary>
/// 分页样式表url
/// </summary>
public string CssUrl
{
get { return cssUrl; }
set { this.cssUrl = value; }
}
/// <summary>
/// 当前页数
/// </summary>
public int CurretPage
{
get { return this.curretPage; }
set { this.curretPage = value; }
}
/// <summary>
/// 传递的参数值
/// </summary>
public string ID
{
get { return this.id; }
set { this.id = value; }
}
/// <summary>
/// 数据开始值(该字段只读)
/// </summary>
public int StartID
{
get
{
if (curretPage == 1)
{
return 0;
}
else
{
return (curretPage-1) * dataCount;
}
}
}
/// <summary>
/// 数据结束的值(该字段只读)
/// </summary>
public int EndID
{
get
{
if (CurretPage == PageCount)
{
return this.DT.Rows.Count;
}
else
{
return (curretPage) * dataCount;
}
}
}
/// <summary>
/// 用于分页的数据源
/// </summary>
public DataTable DT
{
get { return this.dt; }
set { this.dt = value; }
}
/// <summary>
/// 每页显示的数据条数
/// </summary>
public int DataCount
{
get { return this.dataCount; }
set { this.dataCount = value; }
}
#endregion
/// <summary>
/// 分页方法(生成分页代码的过程)
/// </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("当前" + CurretPage + "/" + PageCount + "页 共" + Count + "条数据");
orderInfoSb.Append("</th><th class=/"previous-off/" style=/"align:right/">");
if (Convert.ToInt32(this.ID) == 1)
{
orderInfoSb.Append("<a href='#' disabled='flase'>首页</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id=1'>首页</a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID )== 1 || this.ID==null || this.ID==string.Empty)
{
orderInfoSb.Append("<a href='#'disabled='flase'></a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(CurretPage-1)+"'></a>");
}
if (Convert.ToInt32(this.ID) < PageCount)
{
orderInfoSb.Append("<a href='" + Url + "?id=" +Convert.ToString(CurretPage + 1) + "'></a>");

}
else
{
orderInfoSb.Append("<a href='#'disabled='flase'></a>");
}
orderInfoSb.Append("</th><th>");
if (Convert.ToInt32(this.ID) == PageCount)
{
orderInfoSb.Append("<a href='#' disabled='flase'>末页</a>");
}
else
{
orderInfoSb.Append("<a href='" + Url + "?id="+Convert.ToString(PageCount)+"'>末页</a>");

}
orderInfoSb.Append("</th></tr></span>");
pt.Text = orderInfoSb.ToString();

}
}

样式大家可以自己添,老实说没什么技术含量。
前台代码:
代码
复制代码 代码如下:
<%@ 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>无标题页</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>

后台代码:
代码
复制代码 代码如下:
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/>";
}
}
}

AspNet技术asp.net url分页类代码,转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。