文章出處

  AspNetPager是asp.net中常用的分頁控件,下載AspNetPager.dll,添加引用,在工具欄就可以看到AspNetPager控件:

  拖過來之后,設置如下屬性:

1         <webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText="第一頁" Font-Size="Small"
2             LastPageText="最后一頁" NextPageText="下一頁" PageSize="5" PrevPageText="上一頁" ShowMoreButtons="False"
3             ShowPageIndex="False" OnPageChanging="AspNetPager1_PageChanging">
4         </webdiyer:AspNetPager>

  后臺cs代碼:

 1         protected void Page_Load(object sender, EventArgs e)
 2         {
 3             if (!IsPostBack)
 4             {
 5                 AspNetPager1.AlwaysShow = true;
 6                 AspNetPager1.PageSize = 1;
 7                 //this.AspNetPager1.RecordCount = noticeBll.Query().Rows.Count;
 8                 DataListDataBind();
 9             }
10         }
11 
12         /// <summary>
13         /// 綁定
14         /// </summary>
15         private void DataListDataBind()
16         {
17             try
18             {
19                 PagedDataSource pds = new PagedDataSource();
20                 //啟用分頁設置
21                 pds.AllowPaging = true;
22                 //單頁顯示條數(AspNetPager1.PageSize分頁控件單頁顯示條數)
23                 pds.PageSize = AspNetPager1.PageSize;
24                 //當前頁索引(AspNetPager1.CurrentPageIndex - 1分頁控件當前頁索引)
25                 pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
26                 //綁定數據源
27                 pds.DataSource = noticeBll.Query().DefaultView;//datatable
28 
29                 //數據Count
30                 AspNetPager1.RecordCount = pds.DataSourceCount;
31 
32                 //Repeater綁定數據
33                 rptList.DataSource = pds;
34                 rptList.DataBind();
35             }
36             catch (Exception ex)
37             {
38                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "<script>alert('" + ex.Message + "')</script>");
39             }
40         }
41 
42         protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
43         {
44             AspNetPager1.CurrentPageIndex = e.NewPageIndex;
45             DataListDataBind();
46         }

  需要修改的地方就是第27行綁定數據源。

  設計器效果:

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()