熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

通過aspnetpager為DataList分頁

2022-06-13   來源: .NET編程 

  今天整了半天才把DataList的分頁搞定下面把我的設計過程給大家講講

  前台代碼

  <div id=newslistdiv>

  <asp:DataList ID=NewsList runat=server Width=px>

  <HeaderTemplate>

  <div>

  <img src=/loginimages/newslistheadgif alt= /></div>

  </HeaderTemplate>

  <ItemTemplate>

  <dl>

  <dd>

  ·<a # class=rlk onclick=windowlocationDetailNewsaspx?ID=<%#Eval(NewsID) %>><%#Eval(NewsTitle) %></a>

  &nbsp;&nbsp;&nbsp;<%#Eval(NewsTime {:yyyyMMdd})%><br />

  </dd>

  </dl>

  </ItemTemplate>

  </asp:DataList>

  </div>

  <div align=center>

  <webdiyer:AspNetPager ID=AspNetPager runat=server PageSize= FirstPageText= 首頁

  LastPageText= 尾頁 NextPageText= 下一頁 OnPageChanged=AspNetPager_PageChanged

  PrevPageText= 上一頁 Width=% AlwaysShow=true CssClass=anpager>

  </webdiyer:AspNetPager>

  </div>

  後台代碼

  protected void Page_Load(object sender EventArgs e)

  {

  if (!IsPostBack)

  {

  BindNewsDatalist();

  }

  }

  //綁定DataList的數據源

  private void BindNewsDatalist()

  {

  FJDWSBusinessLogicLNewsManager lnewsmanager = new FJDWSBusinessLogicLNewsManager();

  thisAspNetPagerRecordCount = lnewsmanagerFindAll()Count;

  PagedDataSource pds = new PagedDataSource();    //定義一個PagedDataSource類來執行分頁功能

  pdsDataSource = lnewsmanagerFindAll();

  pdsAllowPaging = true;

  pdsCurrentPageIndex = AspNetPagerCurrentPageIndex ;

  pdsPageSize = AspNetPagerPageSize;

  thisNewsListDataSource = pds;

  NewsListDataBind();

  }

  protected void AspNetPager_PageChanged(object src EventArgs e)

  {

  //AspNetPagerCurrentPageIndex = eNewPageIndex;

  BindNewsDatalist();

  }


From:http://tw.wingwit.com/Article/program/net/201311/12232.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.