AspNetPager分页控件配置

  AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件:

  拖过来之后,设置如下属性:

1         <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="第一页" Font-Size="Small"
2             LastPageText="最后一页" NextPageText="下一页" PageSize="5" PrevPageText="上一页" ShowMoreButtons="False"
3             ShowPageIndex="False" OnPageChanging="AspNetPager1_PageChanging">
4         </webdiyer:AspNetPager>

  后台cs代码:

 1         protected void Page_Load(object sender, EventArgs e)
 2         {
 3             if (!IsPostBack)
 4             {
 5                 AspNetPager1.AlwaysShow = true;
 6                 AspNetPager1.PageSize = 1;
 7                 //this.AspNetPager1.RecordCount = noticeBll.Query().Rows.Count;
 8                 DataListDataBind();
 9             }
10         }
11 
12         /// <summary>
13         /// 绑定
14         /// </summary>
15         private void DataListDataBind()
16         {
17             try
18             {
19                 PagedDataSource pds = new PagedDataSource();
20                 //启用分页设置
21                 pds.AllowPaging = true;
22                 //单页显示条数(AspNetPager1.PageSize分页控件单页显示条数)
23                 pds.PageSize = AspNetPager1.PageSize;
24                 //当前页索引(AspNetPager1.CurrentPageIndex - 1分页控件当前页索引)
25                 pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
26                 //绑定数据源
27                 pds.DataSource = noticeBll.Query().DefaultView;//datatable
28 
29                 //数据Count
30                 AspNetPager1.RecordCount = pds.DataSourceCount;
31 
32                 //Repeater绑定数据
33                 rptList.DataSource = pds;
34                 rptList.DataBind();
35             }
36             catch (Exception ex)
37             {
38                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "<script>alert('" + ex.Message + "')</script>");
39             }
40         }
41 
42         protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
43         {
44             AspNetPager1.CurrentPageIndex = e.NewPageIndex;
45             DataListDataBind();
46         }

  需要修改的地方就是第27行绑定数据源。

  设计器效果:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值