AspNetPager分页方法实现
2008-03-23 19:35
513 查看
AspNetPager分页控件很不错,参考下别人的资料,整理出来了个自己写的分页程序。当然aspNetPager控件得自己先下载一个。
前台页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ 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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" PageSize="5">
</asp:GridView>
</div>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" PageSize="5" UrlPaging="True"></webdiyer:aspnetpager>
</form>
</body>
</html>
后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Default2 : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
if (!Page.IsPostBack)
...{
Bind();
}
}
protected void Bind()
...{
//数据库操作类,实现取数据放到指定DataTable中。
DbAccess dbAccess = new DbAccess();
DataSet ds=new DataSet();
DataTable dt = new DataTable();
string sql = "select * from HotelPrice ";
dbAccess.FillDataTable(dt, sql, CommandType.Text, null);
DataView dv = dt.DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
this.GridView1.DataSource = pds;
this.GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
...{
Bind();
}
}
前台页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ 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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" PageSize="5">
</asp:GridView>
</div>
<webdiyer:aspnetpager id="AspNetPager1" runat="server" onpagechanged="AspNetPager1_PageChanged" PageSize="5" UrlPaging="True"></webdiyer:aspnetpager>
</form>
</body>
</html>
后台代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class Default2 : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
if (!Page.IsPostBack)
...{
Bind();
}
}
protected void Bind()
...{
//数据库操作类,实现取数据放到指定DataTable中。
DbAccess dbAccess = new DbAccess();
DataSet ds=new DataSet();
DataTable dt = new DataTable();
string sql = "select * from HotelPrice ";
dbAccess.FillDataTable(dt, sql, CommandType.Text, null);
DataView dv = dt.DefaultView;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dv.Count;
pds.DataSource = dv;
pds.AllowPaging = true;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.PageSize = AspNetPager1.PageSize;
this.GridView1.DataSource = pds;
this.GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
...{
Bind();
}
}
相关文章推荐
- aspnetpager 分页存储过程的实现
- asp.net利用后台实现直接生成html分页的方法
- Gridview各种功能+AspNetPager+Ajax实现无刷新存储过程分页
- asp.net实现access数据库分页的方法
- ASP+FSO+框架实现ASP生成htm并分页的方法(批量)
- Gridview各种功能+AspNetPager+Ajax实现无刷新存储过程分页
- Asp.Net分页方法:JQuery插件实现Ajax无刷新分页、AspNetPager分页控件实现分页
- aspnetpager 分页存储过程的实现 全代码
- aspnetpager的2种分页方法
- aspnetpager+repeater+oracle实现分页功能
- dhl:asp.net mvc下用jQuery ajax方法实现无刷新分页(用户控件)& 整体页面无刷新(2010-11-13 add)
- ASP+FSO+框架实现ASP生成htm并分页的方法(批量)
- AspNetPager+access 实现 分页 代码
- AspNetPager+GridView实现分页的实例代码
- Aspnetpager+GridView+oracle实现分页功能
- aspnetpager+repeater+oracle实现分页功能
- Asp.net里实现分页浏览方法大总结
- AspNetPager + GridView + ASP.NET AJAX 分页无刷新实现
- AspNetPager分页控件的使用方法
- asp.net利用后台实现直接生成html分页的方法