一步步打造自己的分页控件--1
asp.net数据绑定控件内置了分页功能,但是分页功能有限,样式不好控制,于是想自己开发分页控件
先晒晒图片效果 不要见笑哦
先晒晒前台页面分页代码前台用到的是linkbutton然后触发事件改变页码 绑定到下拉列表控件里面需要知道总页数pagedatasource的属性PageCount
<div id="showTfenye">
当前页:<asp:Label ID="lblPage" runat="server" Text="1"></asp:Label> 总页数:<asp:Label
ID="lblBackPage" runat="server" Text=""></asp:Label>
<asp:LinkButton ID="lbtnOne" runat="server" ForeColor="Red" OnClick="lbtnOne_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lbtnUp" runat="server" ForeColor="Red" OnClick="lbtnUp_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lbtnNext" runat="server" ForeColor="Red" OnClick="lbtnNext_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lbtnBack" runat="server" ForeColor="Red" OnClick="lbtnBack_Click">末页</asp:LinkButton>
<asp:DropDownList ID="DropDownList1" runat="server" Width="40px">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" BackColor="#99FFCC" BorderColor="#3333FF"
BorderWidth="2px" OnClick="Button1_Click" Text="Go" />
</div>
这个分页我是封装在用户控件里面,用pagedatasource作为中间中间数据源,然后传给数据绑定控件比如,GridView
重要的利用pageDataSource的
ps.DataSource = dt.DefaultView;
//是否可以分页
ps.AllowPaging = true;
//显示分页的数量
ps.PageSize = this.ShowCount;
//取得当前页的页码
ps.CurrentPageIndex = curPage - 1;
//显示分页数量
this.lblBackPage.Text = Convert.ToString(ps.PageCount);
1 using System;
2 using System.Data;
3 using System.Web.UI.WebControls;
4 namespace Pager.controls
5 {
6 public partial class pager1 : System.Web.UI.UserControl
7 {
8 protected void Page_Load(object sender, EventArgs e)
9 {
10 if (!IsPostBack)
11 {
12 bind();
13 showPage();
14 }
15 }
16 #region 定义相关属性
17
18 private DataBoundControl dataControl;
19 public DataBoundControl DataControl
20 {
21 get { return this.dataControl; }
22 set { this.dataControl = value; }
23 }
24 #region 其他数据源控件
25
26 //private BaseDataBoundControl dataControl;//数据源控件类型
27 /// <summary>
28 /// 数据绑定控件
29 /// </summary>
30 //public BaseDataBoundControl DataControl
31 //{
32 // get { return this.dataControl; }
33 // set { this.dataControl = value; }
34 //}
35 //DataList控件
36 //private DataList dataControl;
37 //public DataList DataControl
38 //{
39 // get { return this.dataControl; }
40 // set { this.dataControl = value; }
41 //}
42 //repeater控件
43 //private Repeater dataControl;
44 //public Repeater DataControl
45 //{
46 // get { return this.dataControl; }
47 // set { this.dataControl = value; }
48 //}
49 #endregion
50 private int showCount;//每页数量
51 /// <summary>
52 /// 每页显示的数量
53 /// </summary>
54 public int ShowCount
55 {
56 get { return this.showCount; }
57 set { this.showCount = value; }
58 }
59 private DataTable objSource;//数据源
60 /// <summary>
61 /// DataTable类型的数据源
62 /// </summary>
63 public DataTable Objsource
64 {
65 get { return this.objSource; }
66 set { this.objSource = value; }
67 }
68 #endregion
69
70 #region 分页方法
71 #region 分页
72 /// <summary>
73 /// 分页
74 /// </summary>
75 &nb
补充:Web开发 , ASP.Net ,