本文实例讲述了asp.net控件DataList分页用法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
protected void Page_Load( object sender, EventArgs e) { if (!IsPostBack) { ViewState[ "Page" ] = 0; Bangding(); } } //绑定数据 public void Bangding() { PagedDataSource pds = new PagedDataSource(); pds.DataSource = MerchandiseManager.GetList( "" ); pds.AllowPaging = true ; pds.PageSize = 5; //每页记录数 pds.CurrentPageIndex = Pager; //当前页 lblCurrPage.Text = "第" + (pds.CurrentPageIndex + 1).ToString() + "页 共" + pds.PageCount.ToString() + "页" ; SetEnable(pds); //上下页按钮的有效壮态 dlistMerchand.DataSource = pds; dlistMerchand.DataBind(); } private int Pager { get { return ( int )ViewState[ "Page" ]; } set { ViewState[ "Page" ] = value; } } //下一页 protected void LinkButton1_Click( object sender, EventArgs e) { Pager++; Bangding(); } //上一页 protected void LinkButton2_Click( object sender, EventArgs e) { Pager--; Bangding(); } //上下页按钮的有效壮态 private void SetEnable(PagedDataSource pds) { btnShang.Enabled = true ; btnXia.Enabled = true ; if (pds.IsFirstPage) { btnShang.Enabled = false ; } if (pds.IsLastPage) { btnXia.Enabled = false ; } } |
希望本文所述对大家asp.net程序设计有所帮助。