一个分页控件
发表于:2007-06-30来源:作者:点击数:
标签:
pager.ascx %@ Control Language=c# AutoEventWireup=false Codebehind=pager.ascx.cs Inherits=Web.pagercontrol TargetSchema=http://schemas.microsoft.com/intellisense/ie5% var currentpage=%=pageindex%;//当前第几页 var p=%=pageindex%-1; var sum=%
pager.ascx
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="pager.ascx.cs" Inherits="Web.pagercontrol" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
var currentpage=<%=pageindex%>;//当前第几页
var p=<%=pageindex%>-1;
var sum=<%=sum%>;
var perpage=<%=perpage%>;
var urlstr=@#<%=urlstr%>@#;
var fontcolor=@#<%=fontcolor%>@#;
//n代表一共有多少页
if(sum%perpage==0)
{
n=sum/perpage;
}
else
{
n=(sum-sum%perpage)/perpage+1;
}
document.write (@#<table border="0" cellpadding="0" cellspacing="3" width="<%=tablewidth%>" align="center" >@#);
document.write (@#<form method=post action="@#+urlstr+@#">@#);
document.write (@#<tr style="font-size: 12px;"><
td valign="middle">@#);
document.write (@#页次:<b>@#+currentpage+@# </b>/<b> @#+n+ @#</b>页 每页<b>@#+perpage+@# </b> 共计:<b> @#+sum+@# </b>条数据</td>@#);
document.write (@#<td valign="middle"><div align="right" >分页:@#);
if (currentpage==1)
{
document.write (@#<font face=webdings color="@#+fontcolor+@#">9</font>@#);
}
else
{
document.write (@#<a href="@#+urlstr+@#&page=1" title="首页"><font face=webdings>9</font></a>@#);
}
if (currentpage > 10)
{
document.write (@#<a href="@#+urlstr+@#&page=@#+(currentpage-10)+@#" title="上十页"><font face=webdings>7</font></a> @#);
}
document.write (@#<b>@#);
for (i=p-p%10+1;i<p-p%10+1+11;i++)
{
if (i==n+1) break;
if (i==currentpage)
{
document.write (@# <font color="@#+fontcolor+@#">@#+i+@#</font> @#);
}
else
{
document.write (@# <a href="@#+urlstr+@#&page=@#+i+@#">@#+i+@#</a> @#);
}
}
document.write (@#</b>@#);
if (n-currentpage>10)
{
document.write (@#<a href="@#+urlstr+@#&page=@#+(currentpage+10)+@#" title="下十页"><font face=webdings>8</font></a> @#);
}
if (currentpage==n)
{
document.write (@#<Font face=webdings color="@#+fontcolor+@#">:</font>@#);
}
else
{
document.write (@#<a href="@#+urlstr+@#&page=@#+n+@#" title="尾页"><font face=webdings>:</font></a> @#);
}
document.write (@#转到:<input type=text name=Page size=3 maxlength=10 value="@#+currentpage+@#"><input type=submit value=Go name=submit>@#);
document.write (@#</div></td></tr>@#);
document.write (@#</form></table>@#);
pager.ascx.cs
namespace Web
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// pager1 的摘要说明。
/// </summary>
public class pagercontrol : System.Web.UI.UserControl
{
public string urlstr="page.aspx";
public int pageindex=1;
public int sum=20;
public int perpage=20;
public string tablewidth="100%";
public string fontcolor="black";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
原文转自:http://www.ltesting.net