DLL下载:/Files/prolifes/aspnetpager.rar
不同版本下载地址:http://www.webdiyer.com/download/default.aspx
1.Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!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 id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
<div align="center">
<table>
<tr>
<td>共<%=AspNetPager1.RecordCount%>条记录,每页显示<%=PageSize%>条</td>
<td><webdiyer:AspNetPager id="AspNetPager1" runat="server" AlwaysShow="True" OnPageChanged="AspNetPager1_PageChanged"></webdiyer:AspNetPager></td>
</tr>
</table>
</div>
</form>
</body>
</html>
2.Default.aspx.cs
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<!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 id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>
<div align="center">
<table>
<tr>
<td>共<%=AspNetPager1.RecordCount%>条记录,每页显示<%=PageSize%>条</td>
<td><webdiyer:AspNetPager id="AspNetPager1" runat="server" AlwaysShow="True" OnPageChanged="AspNetPager1_PageChanged"></webdiyer:AspNetPager></td>
</tr>
</table>
</div>
</form>
</body>
</html>
2.Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public int PageSize = 10;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AspNetPager1.PageSize = PageSize;//设置每页显示数
AspNetPager1.RecordCount = GetCount();//得到总记录数
GridViewBinder(AspNetPager1.CurrentPageIndex);
}
}
/// <summary>
/// 得到记录总数
/// </summary>
/// <returns></returns>
private int GetCount()
{
string sql = "select count(*) from Orders";
DataSet dt = FindMange(sql);
return int.Parse(dt.Tables[0].Rows[0][0].ToString());
}
/// <summary>
/// 绑定
/// </summary>
/// <param name="Page"></param>
private void GridViewBinder(int Page)
{
string sql = "select top " + PageSize + " * from Orders where OrderId not in(select top " + (Page - 1) * PageSize + " OrderId from Orders order by OrderId) order by OrderId";
DataSet dt = FindMange(sql);
GridView1.DataSource = dt.Tables[0];
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GridViewBinder(AspNetPager1.CurrentPageIndex);
}
private DataSet FindMange(string sql)
{
string conSQL = "server=.;uid=sa;pwd=123;database=northwind";
SqlConnection objConn = new SqlConnection(conSQL);
try
{
objConn.Open();
DataSet dt = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, objConn);
da.Fill(dt);
objConn.Close();
objConn.Dispose();
return dt;
}
catch (SqlException e)
{
throw e;
}
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
public int PageSize = 10;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AspNetPager1.PageSize = PageSize;//设置每页显示数
AspNetPager1.RecordCount = GetCount();//得到总记录数
GridViewBinder(AspNetPager1.CurrentPageIndex);
}
}
/// <summary>
/// 得到记录总数
/// </summary>
/// <returns></returns>
private int GetCount()
{
string sql = "select count(*) from Orders";
DataSet dt = FindMange(sql);
return int.Parse(dt.Tables[0].Rows[0][0].ToString());
}
/// <summary>
/// 绑定
/// </summary>
/// <param name="Page"></param>
private void GridViewBinder(int Page)
{
string sql = "select top " + PageSize + " * from Orders where OrderId not in(select top " + (Page - 1) * PageSize + " OrderId from Orders order by OrderId) order by OrderId";
DataSet dt = FindMange(sql);
GridView1.DataSource = dt.Tables[0];
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GridViewBinder(AspNetPager1.CurrentPageIndex);
}
private DataSet FindMange(string sql)
{
string conSQL = "server=.;uid=sa;pwd=123;database=northwind";
SqlConnection objConn = new SqlConnection(conSQL);
try
{
objConn.Open();
DataSet dt = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql, objConn);
da.Fill(dt);
objConn.Close();
objConn.Dispose();
return dt;
}
catch (SqlException e)
{
throw e;
}
}
}