当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net url分页类代码

ASP.NET
ASP.NET开发:简化应用程序的开发支持Web标准
asp.net XMLHttpRequest实现用户注册前的验证
asp.net 页面间传值方法小结
asp.net url重写浅谈
asp.net 验证码生成和刷新及验证
C#精髓 GridView72大绝技 学习gridview的朋友必看
实例说明asp.net中的简单角色权限控制
asp.net网站开发包wq.dll打包下载
js与ASP.NET 中文乱码问题
asp.net checkbox 动态绑定id GridView删除提示
asp.net TextBox回车触发事件 图片在img显示
asp.net 脏字典过滤问题 用正则表达式来过滤脏数据
asp.NET 脏字过滤算法
asp.NET 脏字过滤算法 修改版
asp.net sql 数据库处理函数命令
asp.net Javascript 的几种写法与提示
ASP.NET MVC学习笔记
asp.net 中国身份证号码验证代码 非正则
Asp.net中使用Sqlite数据库的方法
asp.net 中文字符串提交乱码的解决方法

ASP.NET 中的 asp.net url分页类代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 64 ::
收藏到网摘: n/a

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/>";
}
}
}