AspNetPager分页控件使用方法

1.在vs web应用程序项目里引用AspNetPager.dll,在工具箱中添加AspNetPager控件。

2.在aspx里面拖入AspNetPager控件,设定分页控件每页显示条目数PageSize。

  例:

<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
             UrlPaging="true"
             FirstPageText="首页" PrevPageText="上一页" NextPageText="下一页" LastPageText="尾页" 
                AlwaysShow="True" onpagechanged="AspNetPager1_PageChanged" PageSize="2" 
                CurrentPageButtonStyle="whitefont" PageIndexBoxType="DropDownList" 
                ShowPageIndexBox="Always">
            </webdiyer:AspNetPager>

拖入控件后会在网页头部添加如下代码:

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

3.在aspx.cs文件Page_Load方法里设置AspNetPager控件的RecordCount。

  例:通过连接数据库获取需要显示信息的条目数

1 if (!this.IsPostBack)  //判断网页首次载入
2             {
3                 int recordCount = int.Parse(SqlConnectOpr.ExecuteScalar("SELECT COUNT(*) FROM MessageType", null).ToString());  //链接数据库获取条目数
4                 this.AspNetPager1.RecordCount = recordCount;  //设定ID为AspNetPager1的分页控件的RecordCount属性值,即总条目数。
5             }

4.设定分页控件的urlPaging为true。

5.修改分页控件的PageChanged函数。

1 protected void AspNetPager1_PageChanged(object sender, EventArgs e)
2         {
3             int currentPage = 1;   //默认显示第一页。
4             if (!string.IsNullOrEmpty(Request.QueryString["page"]))
5             {
6                 currentPage = int.Parse(Request.QueryString["page"]);
7             }   //通过网页get方式获取当前页码。
8             this.DataBindToPage(2, currentPage);  //链接数据库并显示需要显示的数据条目,2为每页显示条目数。
9         }

 

 

转载于:https://www.cnblogs.com/Leroy1245/archive/2012/08/09/2630365.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值