AspNetPager分页控件采用URL分页机制,高效简洁
前台:

Code
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<div class="pager" >
<webdiyer:aspnetpager id="PageCtrl" runat="server" CustomInfoSectionWidth="100%" UrlPaging="True" Font-Bold="False" Font-Size="13pt" Font-Strikeout="False" Font-Underline="False" OnPageChanged="PageCtrl_PageChanged" ></webdiyer:aspnetpager>
</div>
后台:

Code
1
private string _beginTime = "";
2
private string _endTime = "";
3
private string _isActive = "";
4
private string _key = "";
5
protected string referrerUrl = "";
6
protected void Page_Load(object sender, EventArgs e)
7
{
8
base.Response.Buffer = true;
9
base.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1.0);
10
base.Response.Expires = 0;
11
base.Response.CacheControl = "no-cache";
12
Utils.CheckAdmin();//检测是否登陆
13
if (!string.IsNullOrEmpty(base.Request.QueryString["key"]))//搜索条件
14
{
15
this._key = base.Request.QueryString["key"].ToString();
16
}
17
if (!string.IsNullOrEmpty(base.Request.QueryString["isActive"]))
18
{
19
this._isActive = base.Request.QueryString["isActive"].ToString();
20
}
21
if (!string.IsNullOrEmpty(base.Request.QueryString["beginTime"]))
22
{
23
this._beginTime = base.Request.QueryString["beginTime"].ToString();
24
}
25
if (!string.IsNullOrEmpty(base.Request.QueryString["endTime"]))
26
{
27
this._endTime = base.Request.QueryString["endTime"].ToString();
28
}
29
this.referrerUrl = Utils.SetReferrerUrl();
30
if (!IsPostBack)
31
{
32
this.RepeaterBind(this.PageCtrl.CurrentPageIndex);
33
InitData();
34
}
35
}
36
public void InitData()
37
{
38
this.txtBeginTime.Attributes.Add("onfocus", "WdatePicker({el:$dp.$('" + this.txtBeginTime.ClientID + "')})");
39
this.txtBeginTime.Attributes.Add("maxdate", "#F{$('" + this.txtEndTime.ClientID + "').value}");
40
this.txtEndTime.Attributes.Add("onfocus", "WdatePicker({el:$dp.$('" + this.txtEndTime.ClientID + "')})");
41
this.txtEndTime.Attributes.Add("mindate", "#F{$('" + this.txtBeginTime.ClientID + "').value}");
42
this.txtBeginTime.Attributes.Add("onPicked", "$('" + this.txtEndTime.ClientID + "').onfocus()");
43
this.chk_All.Attributes.Add("onclick", "SelectAll('chk_All')");
44
}
45
46
//绑定数据源
47
public void RepeaterBind(int currentPageIndex)
48
{
49
Web9eat.BLL.PointBLL bll = new Web9eat.BLL.PointBLL();
50
List<PointInfo> pointinfo;
51
pointinfo = bll.getPointInfo(this._key,this._isActive,this._beginTime,this._endTime);
52
PagedDataSource objPage = new PagedDataSource();
53
objPage.DataSource = pointinfo;
54
int Sum = pointinfo.Count;
55
this.PageCtrl.RecordCount = Sum;
56
this.PageCtrl.PageSize = 12;
57
objPage.AllowPaging = true;
58
objPage.PageSize = 12;
59
objPage.CurrentPageIndex = currentPageIndex - 1;
60
Repeater1.DataSource = objPage;
61
Repeater1.DataBind();
62
}
63
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
64
{
65
Literal lblState = (Literal)e.Item.FindControl("lblState");
66
if (lblState != null)
67
{
68
if (lblState.Text == "False")
69
{
70
lblState.Text = "未激活";
71
}
72
else
73
{
74
lblState.Text = "已激活";
75
}
76
}
77
}
78
protected void PageCtrl_PageChanged(object sender, EventArgs e)
79
{
80
this.RepeaterBind(this.PageCtrl.CurrentPageIndex);
81
}
82
83
//查询条件
84
protected void Button1_Click(object sender, EventArgs e)
85
{
86
string parm = "";
87
if (this.txtKey.Text != "")
88
{
89
parm = parm + "&key=" + this.txtKey.Text;
90
}
91
if (this.txtBeginTime.Text != "")
92
{
93
parm = parm + "&beginTime=" + this.txtBeginTime.Text;
94
}
95
if (this.txtEndTime.Text != "")
96
{
97
parm = parm + "&endTime=" + this.txtEndTime.Text;
98
}
99
if (!string.IsNullOrEmpty(base.Request.Form["radIsActive"]) && (base.Request.Form["radIsActive"].ToString() != ""))
100
{
101
parm = parm + "&isActive=" + base.Request.Form["radIsActive"].ToString();
102
}
103
if (parm != "")
104
{
105
parm = parm.Remove(0, 1);
106
}
107
base.Response.Redirect("PointList.aspx?" + parm);
108
}
109