Using System; Using System. Collections. Generic; Using System. Web. UI; Using Common; Namespace Web { Public partial class _ Default: System. Web. UI. Page { Private static ListPager lp = null; Private static int currentIndex = 1; Private static int pageSize = 5; Protected void Page_Load (object sender, EventArgs e) { If (! Page. IsPostBack) { BindRepeater (1, pageSize ); } } Private void BindRepeater (int index, int pageSize) { BLLDemo. NewsBll optNews = new BLLDemo. NewsBll (); List list = optNews. GetModels (); Lp = new ListPager (list, index, pageSize ); RptNews. DataSource = lp; RptNews. DataBind (); BindPagerControls (); } Private void BindPagerControls () { // Determine whether the previous page and next page buttons are enabled. BtnPrevious. Enabled = currentIndex! = 1; BtnNext. Enabled = currentIndex! = Lp. PageCount; LblCurrentPage. Text = lp. CurrentIndex. ToString (); LblTotalPage. Text = lp. PageCount. ToString (); LblPageInfo. Text = String. Format ("{0} records in total, {1} records per page", lp. TotalItem, lp. PageSize ); } Protected void btnprevius_click (object sender, EventArgs e) { -- CurrentIndex; BindRepeater (currentIndex, pageSize ); BindPagerControls (); } Protected void btnNext_Click (object sender, EventArgs e) { ++ CurrentIndex; BindRepeater (currentIndex, pageSize ); BindPagerControls (); } Protected void btnFirstPage_Click (object sender, EventArgs e) { CurrentIndex = 1; // corrected to 1. It was written as 0 at the first sending, and 2B ~ BindRepeater (currentIndex, pageSize ); } Protected void btnLastPage_Click (object sender, EventArgs e) { CurrentIndex = lp. PageCount; BindRepeater (currentIndex, pageSize ); } } } |