使用AspNetPager分页控件、分页存储过程及用户控件基类实现的完美分页功能
分页原来可以如此简单:
一、分页存储过程
二、需要分页的用户控件基类(里面还有一些信息提示的功能):
三、需要分页的用户控件前台代码:
四、需要分页的用户控件后台代码:
好,大功告成了。这个用户控件,在Aspx里调用的时候,还可以加参数,比如页大小,条件,排序等。
<uc:ItemPageList ID="list" runat="server" PageSize="20" OrderBy="Id Desc" Where="Id < 200 and AddTime < getdate()" />
一、分页存储过程
1
/*
2
declare @P1 int,@p2 int
3
set @P1=NULL
4
exec sp_PageView @tbname = N'sim_NoteBook', @FieldKey = N'Id', @PageCurrent = 3, @PageSize = 10, @FieldShow = N'', @FieldOrder = N'Id', @Where = N'', @ItemCount=@p2 output,@PageCount = @P1 output
5
select @P1
6
select @p2
7![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
exec sp_PageView 'sim_NoteBook', 'Id',@ItemCount=NULL,@PageCount=NULL
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
exec sp_PageView @tbname = N'sim_NoteBook', @FieldKey = N'Id', @PageCurrent = 1, @PageSize = 10, @FieldShow = N'', @FieldOrder = N'Id Desc', @Where = N'', @ItemCount = 0, @PageCount = 0
12
*/
13
CREATE PROC sp_PageView
14
@tbname sysname, --要分页显示的表名
15
@FieldKey nvarchar(1000), --用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段
16
@PageCurrent int=1, --要显示的页码
17
@PageSize int=10, --每页的大小(记录数)
18
@FieldShow nvarchar(1000)='', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段
19
@FieldOrder nvarchar(1000)='', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC,用于指定排序顺序
20
@Where nvarchar(1000)='', --查询条件
21
@ItemCount int OUTPUT,
22
@PageCount int OUTPUT --总页数
23
AS
24
SET NOCOUNT ON
25
--检查对象是否有效
26
IF OBJECT_ID(@tbname) IS NULL
27
BEGIN
28
RAISERROR(N'对象"%s"不存在',1,16,@tbname)
29
RETURN
30
END
31
IF OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTable')=0
32
AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsView')=0
33
AND OBJECTPROPERTY(OBJECT_ID(@tbname),N'IsTableFunction')=0
34
BEGIN
35
RAISERROR(N'"%s"不是表、视图或者表值函数',1,16,@tbname)
36
RETURN
37
END
38
--分页字段检查
39
IF ISNULL(@FieldKey,N'')=''
40
BEGIN
41
RAISERROR(N'分页处理需要主键(或者惟一键)',1,16)
42
RETURN
43
END
44
--其他参数检查及规范
45
IF ISNULL(@PageCurrent,0)<1 SET @PageCurrent=1
46
IF ISNULL(@PageSize,0)<1 SET @PageSize=10
47
IF ISNULL(@FieldShow,N'')=N'' SET @FieldShow=N'*'
48
IF ISNULL(@FieldOrder,N'')=N''
49
SET @FieldOrder=N''
50
ELSE
51
SET @FieldOrder=N'ORDER BY '+LTRIM(@FieldOrder)
52
IF ISNULL(@Where,N'')=N''
53
SET @Where=N''
54
ELSE
55
SET @Where=N'WHERE ('+@Where+N')'
56
--如果@PageCount为NULL值,则计算总页数(这样设计可以只在第一次计算总页数,以后调用时,把总页数传回给存储过程,避免再次计算总页数,对于不想计算总页数的处理而言,可以给@PageCount赋值)
57![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
58
DECLARE @sql nvarchar(4000)
59
SET @sql=N'SELECT @ItemCount=COUNT(*)'
60
+N' FROM '+@tbname
61
+N' '+@Where
62
EXEC sp_executesql @sql,N'@ItemCount int OUTPUT',@ItemCount OUTPUT
63
SET @PageCount=(@ItemCount+@PageSize-1)/@PageSize
64![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
65
print @PageCount
66
print @ItemCount
67
--计算分页显示的TOPN值
68
DECLARE @TopN varchar(20),@TopN1 varchar(20)
69
SELECT @TopN=@PageSize,
70
@TopN1=(@PageCurrent-1)*@PageSize
71
--第一页直接显示
72
IF @PageCurrent=1
73
EXEC(N'SELECT TOP '+@TopN
74
+N' '+@FieldShow
75
+N' FROM '+@tbname
76
+N' '+@Where
77
+N' '+@FieldOrder)
78
ELSE
79
BEGIN
80
--处理别名
81
IF @FieldShow=N'*'
82
SET @FieldShow=N'a.*'
83
--生成主键(惟一键)处理条件
84
DECLARE @Where1 nvarchar(4000),@Where2 nvarchar(4000),
85
@s nvarchar(1000),@Field sysname
86
SELECT @Where1=N'',@Where2=N'',@s=@FieldKey
87
WHILE CHARINDEX(N',',@s)>0
88
SELECT @Field=LEFT(@s,CHARINDEX(N',',@s)-1),
89
@s=STUFF(@s,1,CHARINDEX(N',',@s),N''),
90
@Where1=@Where1+N' AND a.'+@Field+N'=b.'+@Field,
91
@Where2=@Where2+N' AND b.'+@Field+N' IS NULL',
92
--@Where=REPLACE(@Where,@Field,N'a.'+@Field),
93
@FieldOrder=REPLACE(@FieldOrder,@Field,N'a.'+@Field),
94
@FieldShow=REPLACE(@FieldShow,@Field,N'a.'+@Field)
95
SELECT --@Where=REPLACE(@Where,@s,N'a.'+@s),
96
@FieldOrder=REPLACE(@FieldOrder,@s,N'a.'+@s),
97
@FieldShow=REPLACE(@FieldShow,@s,N'a.'+@s),
98
@Where1=STUFF(@Where1+N' AND a.'+@s+N'=b.'+@s,1,5,N''),
99
@Where2=CASE
100
WHEN @Where='' THEN N'WHERE ('
101
ELSE @Where+N' AND ('
102
END+N'b.'+@s+N' IS NULL'+@Where2+N')'
103
DECLARE @QUERYSTRING varchar(2000)
104
SET @QUERYSTRING = N'SELECT TOP '+@TopN
105
+N' '+@FieldShow
106
+N' FROM '+@tbname
107
+N' a LEFT JOIN(SELECT TOP '+@TopN1
108
+N' '+@FieldKey
109
+N' FROM '+@tbname
110
+N' a '+@Where
111
+N' '+@FieldOrder
112
+N')b ON '+@Where1
113
+N' '+@Where2
114
+N' '+@FieldOrder
115
PRINT @QUERYSTRING
116
--执行查询
117
EXEC(@QUERYSTRING)
118![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
119![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
120
END
121
GO
122![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
87
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
88
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
89
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
90
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
91
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
92
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
93
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
94
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
95
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
96
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
97
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
98
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
99
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
100
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
101
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
102
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
103
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
104
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
105
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
106
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
107
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
108
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
109
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
110
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
111
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
112
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
113
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
114
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
115
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
116
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
117
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
118
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
119
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
120
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
121
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
122
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
二、需要分页的用户控件基类(里面还有一些信息提示的功能):
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Web.UI;
5
using System.Web.UI.WebControls;
6
using Wuqi.Webdiyer;
7![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
namespace Foundway.Project.Web
9
{
10
public class UserControlBase : UserControl
11
{
12
protected override void OnLoad(EventArgs e)
13
{
14
base.OnLoad(e);
15![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
Label labelMsg = this.FindControl("labelMsg") as Label;
17
if (labelMsg != null)
18
{
19
labelMsg.Visible = false;
20
}
21
}
22![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
protected void ShowMessage(string message)
24
{
25
Label labelMsg = this.FindControl("labelMsg") as Label;
26
if (labelMsg != null)
27
{
28
labelMsg.Visible = true;
29
labelMsg.Text = message;
30
}
31
}
32![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
protected void ShowMessage(string message, Exception exp)
34
{
35
Label labelMsg = this.FindControl("labelMsg") as Label;
36
if (labelMsg != null)
37
{
38
labelMsg.Visible = true;
39
labelMsg.Text = message + "。详情为:" + exp.Message;
40
}
41
}
42![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
protected void AlertMessage(string message)
44
{
45
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", String.Format(@"alert(""{0}"");", message), true);
46
}
47![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
protected void AlertMessage(string message, string redirecturl)
49
{
50
AlertMessage(message, redirecturl, false);
51
}
52![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
protected void AlertMessage(string message, string redirecturl, bool canBack)
54
{
55
Response.Clear();
56![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
if (canBack)
58
Response.Write(String.Format(@"<script>alert(""{0}"");location.href='{1}';</script>", message, redirecturl));
59
else
60
Response.Write(String.Format(@"<script>alert(""{0}"");location.replace('{1}');</script>", message, redirecturl));
61![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
Response.End();
63
}
64
}
65![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
public class ListUserControlBase : UserControlBase
67
{
68
// Fields
69
protected int ItemCount;
70![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
// Properties
72
public string OrderBy
73
{
74
get
75
{
76
if (this.ViewState["__OrderBy"] == null)
77
{
78
this.ViewState["__OrderBy"] = "";
79
}
80
return this.ViewState["__OrderBy"].ToString();
81
}
82
set
83
{
84
this.ViewState["__OrderBy"] = value;
85
}
86
}
87![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88
public string Where
89
{
90
get
91
{
92
if (this.ViewState["__Where"] == null)
93
{
94
this.ViewState["__Where"] = "1=1";
95
}
96
return this.ViewState["__Where"].ToString();
97
}
98
set
99
{
100
this.ViewState["__Where"] = value;
101
}
102
}
103
}
104![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
105
public class PageUserControlBase : ListUserControlBase
106
{
107
// Fields
108
protected int PageCount;
109
protected AspNetPager pagerBottom;
110
protected AspNetPager pagerTop;
111![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
112
// Methods
113
protected virtual void BindData(int pageIndex)
114
{
115
this.PageIndex = pageIndex;
116
if (this.pagerTop != null)
117
{
118
this.pagerTop.PageSize = this.PageSize;
119
this.pagerTop.RecordCount = base.ItemCount;
120
this.pagerTop.CurrentPageIndex = pageIndex;
121
}
122
if (this.pagerBottom != null)
123
{
124
this.pagerBottom.PageSize = this.PageSize;
125
this.pagerBottom.RecordCount = base.ItemCount;
126
this.pagerBottom.CurrentPageIndex = pageIndex;
127
}
128
}
129![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
130
protected virtual void OnPageChanged(object sender, EventArgs e)
131
{
132
AspNetPager pager = (AspNetPager)sender;
133
this.BindData(pager.CurrentPageIndex);
134
}
135![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
136
// Properties
137
public int PageIndex
138
{
139
get
140
{
141
if (this.ViewState["__PageIndex"] == null)
142
{
143
this.ViewState["__PageIndex"] = 1;
144
}
145
return Convert.ToInt32(this.ViewState["__PageIndex"]);
146
}
147
set
148
{
149
this.ViewState["__PageIndex"] = value;
150
}
151
}
152![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
153
public int PageSize
154
{
155
get
156
{
157
if (this.ViewState["__PageSize"] == null)
158
{
159
this.ViewState["__PageSize"] = 10;
160
}
161
return Convert.ToInt32(this.ViewState["__PageSize"]);
162
}
163
set
164
{
165
this.ViewState["__PageSize"] = value;
166
}
167
}
168
}
169![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
170
}
171![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
68
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
69
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
70
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
71
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
72
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
74
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
76
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
77
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
78
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
79
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
80
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
81
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
82
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
83
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
84
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
85
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
86
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
87
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
88
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
89
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
90
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
91
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
92
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
94
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
95
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
96
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
97
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
98
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
99
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
100
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
101
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
102
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
103
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
104
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
105
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
106
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
107
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
108
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
109
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
110
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
111
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
112
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
113
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
114
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
115
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
116
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
117
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
118
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
119
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
120
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
121
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
122
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
123
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
124
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
125
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
126
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
127
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
128
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
129
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
130
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
131
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
132
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
133
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
134
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
135
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
136
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
137
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
138
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
139
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
140
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
141
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
142
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
143
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
144
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
145
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
146
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
147
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
148
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
149
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
150
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
151
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
152
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
153
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
154
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
155
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
156
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
157
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
158
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
159
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
160
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
161
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
162
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
163
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
164
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
165
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
166
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
167
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
168
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
169
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
170
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
171
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
三、需要分页的用户控件前台代码:
1
<%@ Control Language="C#" Inherits="GotAspx.Sample.Facade.Controls.ItemPageList" %>
2![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
记录列表
4
<asp:DivLabel ID="labelMsg" runat="server"></asp:DivLabel>
5
<asp:Repeater id="repeaterItem" runat="server">
6
<HeaderTemplate><table>
7
<tr>
8
<th>序号</th>
9
<th>名称</th>
10
</tr>
11
</HeaderTemplate>
12
<FooterTemplate></table></FooterTemplate>
13
<ItemTemplate>
14
<tr>
15
<td><%# Container.ItemIndex + 1 %></td>
16
<td><%# Eval("Name") %></td>
17
</tr>
18
</ItemTemplate>
19
</asp:Repeater>
20
<asp:AspNetPager ID="pagerBottom" runat="server" OnPageChanged="OnPageChanged" />
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
四、需要分页的用户控件后台代码:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Web.UI.WebControls;
5
using System.Data;
6
using Foundway.Project.Data.Sql;
7![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
namespace GotAspx.Sample.Facade.Controls
9
{
10
public class ItemPageList : PageUserControlBase
11
{
12
protected Repeater repeaterItem;
13![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
protected override void OnLoad(EventArgs e)
15
{
16
base.OnLoad(e);
17![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
if (!Page.IsPostBack)
19
{
20
BindData(1);
21
}
22
}
23![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
protected override void BindData(int pageIndex)
25
{
26
//此处为调用分页存储过程
27
DataSet ds = DbUtility.QueryPagerData("jc_Province", "Id", pageIndex, PageSize, "", OrderBy, Where, out ItemCount, out PageCount);
28
if (ItemCount > 0)
29
{
30
repeaterItem.Visible = true;
31
repeaterItem.DataSource = ds;
32
repeaterItem.DataBind();
33
}
34
else
35
{
36
repeaterItem.Visible = false;
37
ShowMessage("还没有添加记录");
38
}
39![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
base.BindData(pageIndex);
41
}
42
}
43
}
44![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
好,大功告成了。这个用户控件,在Aspx里调用的时候,还可以加参数,比如页大小,条件,排序等。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)