该控件成形如图:
主要功能如下:
用户设置每页行数 (或者不设置 则该控件默认每页10笔数据)
用户设置分页控件的数据源DataTable(或者输入查询sql)
该控件会先将传入的数据源保存到session(这样之后就不用重复查询)
然后根据用户的操作(第一页、上一页,下一页,最后页,Go页)
以及当前所在的页码
得到符合条件的返回数据 (即点击下一页或上一页后 需要正确显示的数据集)
同时 可以根据数据是否多于一页 来决定该控件是否需要显示
然后用户可以选用 这返回的DataTable数据集进行相关操作
(本控件 已加入部分js判断)
==============
示例源代码如下:
++++++++++++++++++
PageIndexCtl.ascx
+++++++++++++
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PageIndexCtl.ascx.cs" Inherits="Controls_PageIndexCtl" %>
<table>
<tr id="tr_PageIndex" runat="server">
<td>
<asp:LinkButton ID="lbtn_FirstPage" runat="server" OnClick="lbtn_FirstPage_Click" >第一页</asp:LinkButton>
<asp:LinkButton ID="lbtn_PrePage" runat="server" OnClick="lbtn_PrePage_Click" >上一页</asp:LinkButton>
<asp:LinkButton ID="lbtn_NextPage" runat="server" OnClick="lbtn_NextPage_Click" >下一页</asp:LinkButton>
<asp:LinkButton ID="lbtn_LastPage" runat="server" OnClick="lbtn_LastPage_Click" >最后页</asp:LinkButton>
</td>
</tr>
<tr align="center" id="tr_GoPage" runat="server">
<td>
当前第
<asp:TextBox ID="txt_CurrPage" runat="server" Width="30px" Text="1"></asp:TextBox>
<asp:TextBox ID="txt_CurrPageReal" runat="server" Width="30px" Text="1" style="display:none;"></asp:TextBox>
页/共
<asp:TextBox ID="txt_TotalPage" runat="server" Width="30px" ReadOnly="True" Text="1"></asp:TextBox>
页
<asp:Button ID="btn_GoPage" runat="server" Text="GO" OnClick="btn_GoPage_Click"/></td>
</tr>
</table>
+++++++++++++++++++++
PageIndexCtl.ascx.cs
+++++++++++++++++++++
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12using Gentle.Common;
13using Gentle.Framework;
14using Gentle.Provider;
15
16
17
18/**//*
19 * 作者:Free
20 * 日期:2006/12/28
21 * 名称:系统所用的页面导航: 第一页 上一页 下一页 最后页 当前为第几页/共多少页
22 * 描述:
23 */
24
25public partial class Controls_PageIndexCtl : System.Web.UI.UserControl
26{
27
28 属性声明与公开#region 属性声明与公开
29
30 本控件所需要参数#region 本控件所需要参数
31
32 //私有声明
33 #region
34
35 private string selectSQL;
36
37 private bool isHavedData = true;
38
39 private int currPage = 1;
40 private int totalPage = 1;
41 private int countPerPage = 10;
42
43 private bool isAutoVisible = true;
44
45 private DataTable dt_result;
46
47 #endregion
48
49 //公开属性
50 #region
51
52 /**//// <summary>
53 /// 查询出数据的SQL语句 注意要有Order By
54 /// </summary>
55 [DataSysDescription("查询出数据的SQL语句 注意要有Order By")]
56 public string SelectSQL
57 {
58 get { return selectSQL; }
59 set { selectSQL = value; }
60 }
61
62 /**//// <summary>
63 /// 当前页码
64 /// </summary>
65 [DataSysDescription("当前页码")]
66 [DefaultSettingValue("1")]
67 public int CurrPage
68 {
69 get { return currPage; }
70 set { currPage = value;}
71 }
72
73 /**//// <summary>
74 /// 数据总行数/每页行数 = 总页数
75 /// </summary>
76 [DataSysDescription("数据总行数/每页行数 = 总页数")]
77 [DefaultSettingValue("1")]
78 public int TotalPage
79 {
80 get { return totalPage; }
81 set { totalPage = value; }
82 }
83
84 /**//// <summary>
85 /// 每页显示的数据行数
86 /// </summary>
87 [DataSysDescription("每页显示的数据行数")]
88 [DefaultSettingValue("2")]
89 public int CountPerPage
90 {
91 get
92 {
93 string perCountName = this.UniqueID + "CountPerPage";
94 if (ViewState[perCountName] != null)
95 {
96 return Convert.ToInt32(ViewState[perCountName].ToString());
97 }
98 else
99 {
100 return 10;//默认值
101 }
102 }
103 set
104 {
105 string perCountName = this.UniqueID + "CountPerPage";
106 if (ViewState[perCountName] != null)
107 {
108 ViewState[perCountName] = value;
109 }
110 else
111 {
112 ViewState.Add(perCountName, value);
113 }
114 }
115 }
116
117 [DataSysDescription("计算后 所得的DataTable")]
118 public DataTable dt_Result
119 {