用户控件的后台cs文件代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class ToPagesCommon : System.Web.UI.UserControl
13 {
14 #region 实体的属性
15 /// <summary>
16 /// 当前的页数
17 /// </summary>
18 public int CurrenPage;
19 /// <summary>
20 /// 每页的数量
21 /// </summary>
22 public int CountPages=5;
23 /// <summary>
24 /// 总的数据的行数
25 /// </summary>
26 public int TotalCount;
27 /// <summary>
28 /// 总的页数
29 /// </summary>
30 public int TotalPages;
31 /// <summary>
32 /// 获得总页数的方法
33 /// </summary>
34 public void GetTotalPages()
35 {
36 if (TotalCount > 0)
37 {
38 if (TotalCount % CountPages > 0)
39 {
40 TotalPages = TotalCount / CountPages + 1;
41 }
42 else
43 {
44 TotalPages = TotalCount / CountPages;
45 }
46 }
47 }
48 /// <summary>
49 /// 要跳转到的页面地址
50 /// </summary>
51 public string ToUrl;
52
53 #endregion
54
55 /// <summary>
56 /// 分页类的实例化,例子new ToPages(当前第几页, 每页的数量, 总的数据量, 要跳转到的页面地址);
57 /// </summary>
58 protected void Page_Load(object sender, EventArgs e)
59 {
60 if (!IsPostBack)
61 {
62 GetTotalPages();
63 }
64 }
65 }
主页面的后台cs文件代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10
11 public partial class _Default : System.Web.UI.Page
12 {
13 protected void Page_Load(object sender, EventArgs e)
14 {
15 if (!IsPostBack)
16 {
17 #region 分页控件属性设置
18
19
20 ////获得每页的数据行数
21 //ToPagesCommon1.CountPages = ;
22 ////获得总数据行数
23 //ToPagesCommon1.TotalCount=;
24 ////获得总的页数
25 //ToPagesCommon1.TotalPages=;
26 //
27 //当前为第几页
28 if (Request.QueryString["page"] != null)
29 {
30 ToPagesCommon1.CurrenPage = Convert.ToInt32(Request.QueryString["page"].ToString());
31 }
32 else
33 {
34 ToPagesCommon1.CurrenPage = 1;
35 }
36 //要跳转到的页面的路径
37 ToPagesCommon1.ToUrl = "Default.aspx";
38
39
40 #endregion
41 //总数据量
42 ToPagesCommon1.TotalCount = 50;
43 }
44 }
45 }