SqlPager的再次改进(带数字翻页以及翻页样式设置功能)
使用MSDNSqlPager这么久以来,对SqlPager已经有了比较深入的了解了,总的说来,SqlPager是一个不错的分页控件。对于一般的需求已经能够很好的满足,而且性能比较好;但是美中不足的地方是:它只能对不重复的列进行排序,一旦你用于排序的列的数据有重复现象那么就将出现漏掉数据的情况;对于这个情况我目前也没有好的解决方法,唯一的办法就是先在查询中进行排序,然后再生成该查询结果的自动编号列,不过这个功能在SqlServer2000下不好做,在SQL2005中到自带该功能!闲话就到此,下面转入正题!
以前也对SqlPager进行过一些小的修改,不过还是感觉功能上欠缺了一些!由于一个小项目的需要以及我对SqlPager分页的热爱,所以我又对其进行了修改!主要新增功能如下:1.带类似于百度那种数字翻页功能 2.可以为翻页的数字设置样式表中的样式。
如图所示:
属性说明:
在此贴出主要部分代码:(也就是实现数字翻页部分代码,仅供大家参考)
1
/// <summary>
2
/// 数字翻页 开始值
3
/// </summary>
4
protected int NumberPageBegin
5
{
6
get{return Convert.ToInt32(this.ViewState["_NumberPageBegin"]);}
7
set{this.ViewState["_NumberPageBegin"]=value;}
8
}
9![](/Images/OutliningIndicators/None.gif)
10
/// <summary>
11
/// 数字翻页UI
12
/// </summary>
13
/// <param name="cell"></param>
14
private void BuildNumberUI(TableCell cell)
15
{
16
bool isValidPage = (CurrentPageIndex >=0 && CurrentPageIndex <= TotalPages-1);
17
bool canMoveBack = (CurrentPageIndex>0);
18
bool canMoveForward = (CurrentPageIndex<TotalPages-1);
19
bool isFirst=(CurrentPageIndex==0);
20
bool isLast=(CurrentPageIndex==this.TotalPages-1);
21
22
cell.Controls.Add(new LiteralControl(" "));
23
//第一页
24
LinkButton linkfirst=new LinkButton();
25
linkfirst.ID="link_first_0";
26
//linkfirst.ForeColor = ForeColor;
27
linkfirst.ToolTip = "第1页";
28
linkfirst.Text = "1";
29
//linkfirst.Attributes.Add("onclick",this.ClientID+"_"+linkfirst.ClientID+".className='"+this.VisitedCssClass+"'");
30
linkfirst.Click += new EventHandler(linkfirst_Click);
31
linkfirst.Enabled = !isFirst;
32
// if(this.CurrentPageIndex==0)
33
// {
34
// linkfirst.CssClass=this.VisitedCssClass;
35
// }
36
// else
37
// {
38
linkfirst.CssClass=this.NotVisitCssClass;
39
// }
40
cell.Controls.Add(linkfirst);
41
cell.Controls.Add(new LiteralControl(" "));
42![](/Images/OutliningIndicators/InBlock.gif)
43
//前10页
44
LinkButton linkprevten=new LinkButton();
45
int prevten=0;
46
if(this.CurrentPageIndex%10>0&&this.CurrentPageIndex<this.TotalPages-1)
47
{
48
prevten=(this.CurrentPageIndex/10+1)*10;
49
}
50
if(this.CurrentPageIndex%10==0)
51
{
52
prevten=(this.CurrentPageIndex/10-1)*10;
53
}
54
linkprevten.ID="linkprevten_"+prevten.ToString();
55
//linkprevten.ForeColor = ForeColor;
56
linkprevten.ToolTip = "前10页";
57
linkprevten.Text = "
";
58
linkprevten.Click += new EventHandler(linknumber_Click);
59
linkprevten.Enabled = (this.CurrentPageIndex-1)<10?false:true;
60
cell.Controls.Add(linkprevten);
61
cell.Controls.Add(new LiteralControl(" "));
62![](/Images/OutliningIndicators/InBlock.gif)
63
//中间的数字
64
int counter=0;//计数器
65
if((this.CurrentPageIndex+1)%10==0)
66
{
67
this.NumberPageBegin=this.CurrentPageIndex+1;
68
}
69
else if((this.CurrentPageIndex+1)%10==1)
70
{
71
if(this.CurrentPageIndex>=10)
72
{
73
this.NumberPageBegin=this.CurrentPageIndex-10;
74
}
75
else
76
{
77
this.NumberPageBegin=0;
78
}
79
}
80
else
81
{
82
if(this.CurrentPageIndex/10>0&&this.CurrentPageIndex/10<this.TotalPages/10)
83
{
84
this.NumberPageBegin=(this.CurrentPageIndex/10)*10;
85
}
86
if(this.CurrentPageIndex/10>0&&this.CurrentPageIndex/10==this.TotalPages/10)
87
{
88
this.NumberPageBegin=(this.CurrentPageIndex/10)*10;
89
}
90
}
91
for(int i=this.NumberPageBegin;i<this.TotalPages&&counter<10;i++)
92
{
93
LinkButton midLink=new LinkButton();
94
midLink.ID="midLnk_"+i.ToString();
95
midLink.Text=(i+1).ToString();
96
midLink.Click += new EventHandler(linknumber_Click);
97
//midLink.ForeColor = ForeColor;
98
midLink.ToolTip = "第"+(i+1).ToString()+"页";
99
//midLink.Attributes.Add("onfocus",this.ClientID+"_"+midLink.ClientID+".className='"+this.VisitedCssClass+"'");
100
//midLink.Attributes.Add("class",this.VisitedCssClass);
101
102
//this.ClientID+"_"+midLink.ClientID+".className='"+this.VisitedCssClass+"'";
103![](/Images/OutliningIndicators/InBlock.gif)
104
// if(this.CurrentPageIndex==NumberPageBegin)
105
// {
106
// midLink.CssClass=this.VisitedCssClass;
107
// }
108
// else
109
// {
110
midLink.CssClass=this.NotVisitCssClass;
111
// }
112
// if(isFirst||isLast)
113
// {
114
// midLink.Enabled=false;
115
// }
116
// else
117
// {
118
// midLink.Enabled=true;
119
// }
120
//midLink.Enabled=!isFirst||!isLast;
121
cell.Controls.Add(midLink);
122
cell.Controls.Add(new LiteralControl(" "));
123
counter++;
124
}
125
126
//后10页
127
LinkButton linknextten=new LinkButton();
128
int nextten=0;
129
if(this.CurrentPageIndex%10==0&&this.CurrentPageIndex>0)
130
{
131
nextten=(this.CurrentPageIndex/10-1)*10+9;
132
}
133
if(this.CurrentPageIndex%10==0&&this.CurrentPageIndex==0)
134
{
135
nextten=(this.CurrentPageIndex/10)*10+9;
136
}
137
if(this.CurrentPageIndex%10>0)
138
{
139
nextten=(this.CurrentPageIndex/10+1)*10+9;
140
}
141
linknextten.ID="linknextten_"+nextten.ToString();
142
//linknextten.ForeColor = ForeColor;
143
linknextten.ToolTip = "后10页";
144
linknextten.Text = "
";
145
linknextten.Click += new EventHandler(linknumber_Click);
146
linknextten.Enabled = nextten>this.TotalPages?false:true;
147
cell.Controls.Add(linknextten);
148
cell.Controls.Add(new LiteralControl(" "));
149![](/Images/OutliningIndicators/InBlock.gif)
150
//最后一页
151
LinkButton linklast=new LinkButton();
152
linklast.ID="linkfirst_"+(this.TotalPages-1).ToString();
153
//linklast.ForeColor = ForeColor;
154
linklast.ToolTip = "第"+this.TotalPages.ToString()+"页";
155
linklast.Text = this.TotalPages.ToString();
156
//linklast.Attributes.Keys["href"]+=this.ClientID+"_"+linklast.ClientID+".className='"+this.VisitedCssClass+"'";
157
linklast.Click += new EventHandler(linklast_Click);
158
linklast.Enabled = !isLast;
159
// if(this.CurrentPageIndex==this.TotalPages-1)
160
// {
161
// linklast.CssClass=this.VisitedCssClass;
162
// }
163
// else
164
// {
165
linklast.CssClass=this.NotVisitCssClass;
166
// }
167
cell.Controls.Add(linklast);
168
169![](/Images/OutliningIndicators/InBlock.gif)
170
}
数字翻页的事件![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
6
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/InBlock.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/dot.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/InBlock.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/InBlock.gif)
66
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
67
![](/Images/OutliningIndicators/InBlock.gif)
68
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
69
![](/Images/OutliningIndicators/InBlock.gif)
70
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
77
![](/Images/OutliningIndicators/InBlock.gif)
78
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
79
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
88
![](/Images/OutliningIndicators/InBlock.gif)
89
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
90
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/InBlock.gif)
95
![](/Images/OutliningIndicators/InBlock.gif)
96
![](/Images/OutliningIndicators/InBlock.gif)
97
![](/Images/OutliningIndicators/InBlock.gif)
98
![](/Images/OutliningIndicators/InBlock.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/InBlock.gif)
101
![](/Images/OutliningIndicators/InBlock.gif)
102
![](/Images/OutliningIndicators/InBlock.gif)
103
![](/Images/OutliningIndicators/InBlock.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/InBlock.gif)
107
![](/Images/OutliningIndicators/InBlock.gif)
108
![](/Images/OutliningIndicators/InBlock.gif)
109
![](/Images/OutliningIndicators/InBlock.gif)
110
![](/Images/OutliningIndicators/InBlock.gif)
111
![](/Images/OutliningIndicators/InBlock.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/InBlock.gif)
114
![](/Images/OutliningIndicators/InBlock.gif)
115
![](/Images/OutliningIndicators/InBlock.gif)
116
![](/Images/OutliningIndicators/InBlock.gif)
117
![](/Images/OutliningIndicators/InBlock.gif)
118
![](/Images/OutliningIndicators/InBlock.gif)
119
![](/Images/OutliningIndicators/InBlock.gif)
120
![](/Images/OutliningIndicators/InBlock.gif)
121
![](/Images/OutliningIndicators/InBlock.gif)
122
![](/Images/OutliningIndicators/InBlock.gif)
123
![](/Images/OutliningIndicators/InBlock.gif)
124
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
125
![](/Images/OutliningIndicators/InBlock.gif)
126
![](/Images/OutliningIndicators/InBlock.gif)
127
![](/Images/OutliningIndicators/InBlock.gif)
128
![](/Images/OutliningIndicators/InBlock.gif)
129
![](/Images/OutliningIndicators/InBlock.gif)
130
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
131
![](/Images/OutliningIndicators/InBlock.gif)
132
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
133
![](/Images/OutliningIndicators/InBlock.gif)
134
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
135
![](/Images/OutliningIndicators/InBlock.gif)
136
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
137
![](/Images/OutliningIndicators/InBlock.gif)
138
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
139
![](/Images/OutliningIndicators/InBlock.gif)
140
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
141
![](/Images/OutliningIndicators/InBlock.gif)
142
![](/Images/OutliningIndicators/InBlock.gif)
143
![](/Images/OutliningIndicators/InBlock.gif)
144
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/dot.gif)
145
![](/Images/OutliningIndicators/InBlock.gif)
146
![](/Images/OutliningIndicators/InBlock.gif)
147
![](/Images/OutliningIndicators/InBlock.gif)
148
![](/Images/OutliningIndicators/InBlock.gif)
149
![](/Images/OutliningIndicators/InBlock.gif)
150
![](/Images/OutliningIndicators/InBlock.gif)
151
![](/Images/OutliningIndicators/InBlock.gif)
152
![](/Images/OutliningIndicators/InBlock.gif)
153
![](/Images/OutliningIndicators/InBlock.gif)
154
![](/Images/OutliningIndicators/InBlock.gif)
155
![](/Images/OutliningIndicators/InBlock.gif)
156
![](/Images/OutliningIndicators/InBlock.gif)
157
![](/Images/OutliningIndicators/InBlock.gif)
158
![](/Images/OutliningIndicators/InBlock.gif)
159
![](/Images/OutliningIndicators/InBlock.gif)
160
![](/Images/OutliningIndicators/InBlock.gif)
161
![](/Images/OutliningIndicators/InBlock.gif)
162
![](/Images/OutliningIndicators/InBlock.gif)
163
![](/Images/OutliningIndicators/InBlock.gif)
164
![](/Images/OutliningIndicators/InBlock.gif)
165
![](/Images/OutliningIndicators/InBlock.gif)
166
![](/Images/OutliningIndicators/InBlock.gif)
167
![](/Images/OutliningIndicators/InBlock.gif)
168
![](/Images/OutliningIndicators/InBlock.gif)
169
![](/Images/OutliningIndicators/InBlock.gif)
170
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
/// <summary>
2
/// 数字跳转
3
/// </summary>
4
/// <param name="sender"></param>
5
/// <param name="e"></param>
6
private void linknumber_Click(object sender, EventArgs e)
7
{
8
9
LinkButton link=(LinkButton)sender;
10
string linkID=link.ID;
11
int charIndex=linkID.IndexOf("_")+1;
12
int pageID=Convert.ToInt32(linkID.Substring(charIndex,linkID.Length-charIndex));
13
//this.ChangeLnkBtnCssClass(link);
14
15
link.CssClass=this.VisitedCssClass;
16
//((LinkButton)sender).CssClass=this.VisitedCssClass;
17
18
GoToPage(pageID);
19
}
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
如还有不清楚之处可以联系本人!
源代码下载:LJHSqlPager.rar (本人测试调试了一天,希望大家看后多多指教!)