-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagination.ascx.cs
162 lines (142 loc) · 6.09 KB
/
pagination.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Text;
using System.Text.RegularExpressions;
public partial class pagination : System.Web.UI.UserControl
{
public int PageNumber = 1;
public int PageSize = 20;
public int TotalRecords = 0;
public string Default_Url;
public string Pagination_Url;
public bool showFirst = true;
public bool showLast = true;
public string paginationCss = "pagination-small";
public int paginationStyle = 1; // 1: advance, 0: normal
// CssClasses
protected void Page_Load(object sender, EventArgs e)
{
}
public void BindPagination()
{
StringBuilder str = new StringBuilder();
int TotalPages = (int)Math.Ceiling((double)this.TotalRecords / this.PageSize);
int firstbound = 0;
int lastbound = 0;
string ToolTip = "";
if (this.PageNumber > 1)
{
firstbound = 1;
lastbound = firstbound + this.PageSize - 1;
ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + this.TotalRecords + " records";
if (this.showFirst)
{
// First Link
str.Append("<li><a id=\"p_1\" class=\"pagination-css\" href=\"" + this.Default_Url + "\" title=\"" + ToolTip + "\"><i class=\"icon-backward\"></i></a></li>\n");
}
firstbound = ((TotalPages - 1) * this.PageSize);
lastbound = firstbound + this.PageSize - 1;
if (lastbound > this.TotalRecords)
{
lastbound = this.TotalRecords;
}
ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + this.TotalRecords + " records";
// Previous Link Enabled
string PreviousNavigationUrl = "";
int _prevpage = PageNumber - 1;
if (this.PageNumber > 2)
PreviousNavigationUrl = Add_PageNumber(this.Pagination_Url, _prevpage.ToString());
else
PreviousNavigationUrl = this.Default_Url;
int pid = (this.PageNumber - 1);
if (pid < 1) pid = 1;
str.Append("<li><a id=\"pp_" + pid + "\" id=\"pp_" + pid + "\" href=\"" + PreviousNavigationUrl + "\" title=\"" + ToolTip + "\"><i class=\"icon-arrow-left\"></i></a></li>\n");
// Normal Links
str.Append(Generate_Pagination_Links(TotalPages));
if (this.PageNumber < TotalPages)
{
str.Append(Generate_Previous_Last_Links(TotalPages));
}
}
else
{
// Normal Links
str.Append(Generate_Pagination_Links(TotalPages));
// Next Last Links
str.Append(Generate_Previous_Last_Links(TotalPages));
}
plnks.InnerHtml = "<ul class=\"pagination " + this.paginationCss + "\">\n" + str.ToString() + "</ul>\n";
}
private string Generate_Pagination_Links(int TotalPages)
{
StringBuilder str = new StringBuilder();
int firstbound = 0;
int lastbound = 0;
string ToolTip = "";
ArrayList arr = null;
if (this.paginationStyle == 1)
arr= logic.Advance_Pagination(TotalPages, this.PageNumber);
else
arr = logic.Simple_Pagination(TotalPages, 15, this.PageNumber);
if (arr.Count > 0)
{
int i = 0;
string LinkURL = "";
string Item = "";
for (i = 0; i <= arr.Count - 1; i++)
{
Item = arr[i].ToString();
firstbound = ((int.Parse(Item) - 1) * this.PageSize) + 1;
lastbound = firstbound + this.PageSize - 1;
if (lastbound > this.TotalRecords)
lastbound = this.TotalRecords;
ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + this.TotalRecords + " recodrs";
// url settings
// normal search
if (Item == "1")
LinkURL = this.Default_Url;
else
LinkURL = Add_PageNumber(this.Pagination_Url, Item);
string _css = "";
if (arr[i].ToString() == this.PageNumber.ToString())
_css = "class=\"active\"";
str.Append("<li " + _css + "><a id=\"pg_" + arr[i].ToString() + "\" href=\"" + LinkURL + "\" title=\"" + ToolTip + "\">" + arr[i].ToString() + "</a></li>\n");
}
}
return str.ToString();
}
private string Generate_Previous_Last_Links(int TotalPages)
{
StringBuilder str = new StringBuilder();
int _nextpage = PageNumber + 1;
string LastNavigationUrl = Add_PageNumber(this.Pagination_Url, TotalPages.ToString());
string NextNavigationUrl = Add_PageNumber(this.Pagination_Url, _nextpage.ToString());
int firstbound = ((TotalPages - 1) * this.PageSize) + 1;
int lastbound = firstbound + this.PageSize - 1;
if (lastbound > this.TotalRecords)
{
lastbound = this.TotalRecords;
}
string ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + this.TotalRecords + " records";
// Next Link
int pid = (this.PageNumber + 1);
if (pid > TotalPages) pid = TotalPages;
str.Append("<li><a id=\"pn_" + pid + "\" href=\"" + NextNavigationUrl + "\" title=\"" + ToolTip + "\" class=\"pagination-css\"><i class=\"icon-arrow-right\"></i></a></li>\n");
// Last Link
if (this.showLast)
{
ToolTip = "showing " + firstbound + " - " + lastbound + " records of " + this.TotalRecords + " records";
str.Append("<li><a id=\"pl_" + TotalPages + "\" href=\"" + LastNavigationUrl + "\" title=\"" + ToolTip + "\" class=\"pagination-css\"><i class=\"icon-forward\"></i></a></li>\n");
}
return str.ToString();
}
public string Add_PageNumber(string input, string value)
{
return Regex.Replace(input, @"\[p\]", value);
}
}