DataPager控件使用

APSX:

 1 <asp:ListView ID="LvResult" runat="server"        onpagepropertieschanging="LvResult_PagePropertiesChanging" >
 2     .......
 3 </asp:ListView>
 4 <asp:DataPager runat="server"  ID="ContactsDataPager" PageSize="10" PagedControlID="LvResult"> 
 5     <Fields> 
 6         <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowLastPageButton="False" 
 7                    FirstPageText="首页" LastPageText="尾页" 
 8                    NextPageText="下一页" PreviousPageText="上一页" ShowNextPageButton="False" ButtonType="Link" />
 9         <asp:TemplatePagerField> 
10             <PagerTemplate>
11                 <b><%# Container.TotalRowCount>0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0 %></b>
12             </PagerTemplate>
13         </asp:TemplatePagerField> 
14         <asp:NextPreviousPagerField ShowFirstPageButton="False" ShowLastPageButton="True" 
15                    FirstPageText="首页" LastPageText="尾页"  
16                    NextPageText="下一页" PreviousPageText="上一页" ShowNextPageButton="True" ShowPreviousPageButton="False" />
17         <asp:TemplatePagerField>
18             <PagerTemplate> 
19                 <b><%# Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize) %>页 ( 共<%# Container.TotalRowCount%>条记录   每页<%# Container.PageSize%>条) </b> 
20             </PagerTemplate> 
21         </asp:TemplatePagerField> 
22     </Fields> 
23 </asp:DataPager> 

CS:

 1 protected void BtnSearch_Click(object sender, EventArgs e)
 2 {
 3     ContactsDataPager.SetPageProperties(0, 10, false);
 4     BindData();
 5 }
 6 protected void LvResult_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
 7 {
 8     ContactsDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
 9     BindData();
10 }
11 private void BindData()
12 {
13     ......
14 }

 

转载于:https://www.cnblogs.com/zhuhc/p/3455083.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用DataPager控件来实现分页,需要在aspx页面中添加DataPager控件,并将其与ListView控件进行绑定。 以下是一些实现步骤: 1. 在aspx页面中添加ListView控件DataPager控件,如下所示: ``` <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <!-- 数据列表模板 --> </ItemTemplate> </asp:ListView> <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /> </Fields> </asp:DataPager> ``` 2. 在ListView控件后面添加SqlDataSource控件,并设置查询语句,如下所示: ``` <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM MyTable"> </asp:SqlDataSource> ``` 3. 在后台代码中,需要将ListView控件PageSize属性设置为DataPager控件PageSize属性,如下所示: ``` protected void Page_Load(object sender, EventArgs e) { ListView1.PageSize = DataPager1.PageSize; } ``` 4. 最后,在ListView控件中添加PagerSettings属性,并设置为DataPager控件PagerSettings属性,如下所示: ``` <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <!-- 数据列表模板 --> </ItemTemplate> <PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" PageButtonCount="10" /> </asp:ListView> <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"> <Fields> <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" /> </Fields> </asp:DataPager> ``` 这样,每次查询到的数据列表就可以通过DataPager控件进行分页显示了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值