只是我一直忽視的一個控件,最近才發現它很好用。用法也非常簡單。
1.將dll文件添加進項目,在頁面中引用
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
2.將其放入需要的位置,其中有相關參數的設置
<webdiyer:aspnetpager ID="AspNetPager1" runat="server" AlwaysShow="True"
FirstPageText="首頁" LastPageText="末頁" NextPageText="下一頁" PrevPageText="上一頁"
onpagechanged="AspNetPager1_PageChanged" NumericButtonCount="4" PageSize="5">
</webdiyer:aspnetpager>
3.綁定數據
PagedDataSource pd = new PagedDataSource();
pd.DataSource = NewsManager.listNewShow(Ipid);
pd.AllowPaging = true;
if (pd.DataSourceCount > AspNetPager1.PageSize)
{
this.AspNetPager1.AlwaysShow = true;
}
this.AspNetPager1.RecordCount = pd.DataSourceCount;
pd.PageSize = this.AspNetPager1.PageSize;
pd.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex - 1;
DataList1.DataSource = pd;
DataList1.DataBind();
4.頁面生成的代碼,配合設計編寫相關CSS樣式
<div id="AspNetPager1">
<a disabled="true" style="margin-right:5px;">首頁</a><a disabled="true" style="margin-right:5px;">上一頁</a><span style="margin-right:5px;font-weight:Bold;color:red;">1</span><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">2</a><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">下一頁</a><a href="javascript:__doPostBack('AspNetPager1','2')" style="margin-right:5px;">末頁</a>
</div>