The PagedDataSource data binding control and the AspNetPager paging control are used in combination with the list page and pageddatasource page
1. Reference AspNetPager. dll.
2. Place the Repeater data binding control.
<Asp: Repeater ID = "Repeater1" runat = "server"> <ItemTemplate> // bind the displayed list Code </ItemTemplate> </asp: Repeater>
3. Add the AspNetPager page control on the page. The following code is displayed.
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<Webdiyer: aspNetPager ID = "AspNetPager1" CssClass = "paginator" PageSize = "10" AlwaysShow = "true" FirstPageText = "Homepage" homepage = "Previous Page" NextPageText = "next page" CurrentPageIndex = "1 "LastPageText =" last page "runat =" server "OnPageChanged =" aspnetpager?pagechanged "> </webdiyer: aspNetPager>
// Double-click the pagination control protected void AspNetPager1_PageChanged (object sender, EventArgs e) {BindData ();}
4. How to Write and bind data to the. cs file.
Public void BindData () {// The queried data source, which is changed to Data. DataSet ds = new DataSet (); // set PagedDataSource pageSource = new PagedDataSource (); pageSource. allowPaging = true; // sets whether pageSource is pageSource. pageSize = pagerControl. pageSize; // Number of pages pageSource. currentPageIndex = pagerControl. currentPageIndex-1; // This is the current page. Do not subtract 1. PagedDataSource starts from 0. PageSource. DataSource = ds. Table [0]. DefaultView; pagerControl. RecordCount = pageSource. cececount; Repeater1.DataSource = pagerSource; Repeater1.DataBind ();}
5. Results