最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

asp.net url分页类代码

来源:懂视网 责编:小采 时间:2020-11-27 22:43:52
文档

asp.net url分页类代码

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 Syste
推荐度:
导读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 Syste

代码如下:

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

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

asp.net url分页类代码

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 Syste
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top