aspnetpager的2種分頁方法
<webdiyer:AspNetPager ID="AspNetPager1" UrlPaging="True" PageSize="20" runat="server" FirstPageText="首頁" LastPageText="尾頁" NextPageText="下一頁" PagingButtonSpacing="" PrevPageText="上一頁" ></webdiyer:AspNetPager>
方法1.
if (!this.IsPostBack)
{
int CurrentPageIndex = AspNetPager1.CurrentPageIndex;
if (Request["page"] != null) { CurrentPageIndex = int.Parse(Request["page"]); }
BindData(CurrentPageIndex);
}
void BindData(int CurrentPageIndex)
{
datatable dt=....................;
PagedDataSource pds = new PagedDataSource();
AspNetPager1.RecordCount = dt.Rows.Count;
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = CurrentPageIndex;
pds.DataSource = dt.DefaultView;
this.rpMsgList.DataSource = pds; //可以綁定到Gridview 、datalist等數據控件上
this.rpMsgList.DataBind();
}
不需要寫分頁事件代碼,因為UrlPaging="True",使用了URL分頁 &page=1之類的
方法2.存儲過程分頁
if (!this.IsPostBack)
{
int CurrentPageIndex = AspNetPager1.CurrentPageIndex;
if (Request["page"] != null) { CurrentPageIndex = int.Parse(Request["page"]); }
BindData(CurrentPageIndex);
}
void BindData(int CurrentPageIndex)
{
int pageCount = 0;
int Counts = 0;//總記錄數
rpList.DataSource = SqlHelper.PageProcedure("Company,UserInfo,City,County", " UserName ,CompanyName,SName,CityName,CountyName,Contact,CompanyTypeId,Company.addtime as CompanyAddtime,Status,UId", AspNetPager1.PageSize, CurrentPageIndex, 0, " Company.Status asc, Company.addtime ", 1, " where Company.CityId=City.CityId and City.isshow=1 and Company.CountyId=County.CountyId and County.isshow=1 and Company.UId=UserInfoId " + WebComm.StrWhereHelper.Get_Admin_Company_StrWhere(), "CompanyId", ref pageCount, ref Counts);
AspNetPager1.RecordCount = Counts;
AspNetPager1.CurrentPageIndex = CurrentPageIndex;
rpList.DataBind();
}
不需要寫分頁事件代碼,因為UrlPaging="True",使用了URL分頁 &page=1之類的
玉環人力網(又名玉環人才網)是玉環人才吧旗下一流的玉環人力資源招聘行業服務品牌,匯集海量玉環人才,開放玉環人才簡歷和玉環崗位,提供玉環招聘網,玉環人才市場動態行情,玉環勞務派遣,玉環培訓等,是玉環最大的人才網站。
浙公網安備 33010602011771號