您的位置:首页 > 编程语言 > ASP

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();


}


}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: