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 }