標籤:分頁控制項 color 使用 os io 檔案 資料 ar
首先要先引用AspNetPager.dll檔案
然後在<html>上面添加下面代碼:
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
然後在repeater控制項下添加AspNetPager控制項:
<webdiyer:aspnetpager id="AspNetPager1"
runat="server"
PageSize="100"
AlwaysShow="True"
OnPageChanged="AspNetPager1_PageChanged"
ShowCustomInfoSection="left"
CustomInfoSectionWidth=""
ShowPageIndexBox="Always"
PageIndexBoxType="DropDownList"
CustomInfoHTML="共<font color=‘red‘><b>%RecordCount%</b></font>條記錄" FirstPageText="首頁" LastPageText="末頁" NextPageText="下一頁" PrevPageText="上一頁">
</webdiyer:aspnetpager>
接著在後台代碼中分頁:
AspNetPager1.CurrentPageIndex = 1;//設定或擷取當前頁
PagedDataSource pds = new PagedDataSource();//建立資料集
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;設定索引(索引從0開始)
pds.DataSource = new List<SalesCarModel>();//清空資料來源
pds.AllowPaging = true;//是否啟用分頁
pds.PageSize = AspNetPager1.PageSize;//擷取或設定每頁的項數
ucSalesCar.DataBindSource(pds) ;//綁定到資料控制項
BindDatasource();//一個方法:主要是查詢的條件和查詢的結果和對分頁控制項的屬性設定
private void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindDatasource();更新頁數
}
這樣就完成了
---做筆記