1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Text;
5using System.Web;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8
9namespace CustomerControl
10{
11 [DefaultProperty("Text")]
12 [ToolboxData("<{0}:Pager runat=server></{0}:Pager>")]
13 public class Pager : WebControl,INamingContainer
14 {
15 public event PagerHander First;
16 public event PagerHander Prvi;
17 public event PagerHander Next;
18 public event PagerHander Last;
19 public event PagerHander Go;
20
21 public delegate void PagerHander(object sender, PagerEventArgs e);
22
23 //下一页
24 private Button _btnNext;
25 //上一页
26 private Button _btnPrvi;
27 //页码
28 private TextBox txtPage;
29 //到达页码
30 private Button _btnGo;
31 //最后一页
32 private Button _btnLast;
33 //第一页
34 private Button _btnFirst;
35 //当前页
36 private TextBox _txtCurrentPage;
37 //每页的条数
38 private string _PageCount = "10";
39 //总条数
40 private string _RecordCount;
41
42
43
44 [Bindable(true)]
45 [Category("Appearance")]
46 [DefaultValue("10")]
47 [Localizable(true)]
48 public string PageCount
49 {
50 get
51 {
52 _PageCount = (string)ViewState["PageCount"];
53 return ((_PageCount == null) ? "10" : _PageCount);
54 }
55
56 set
57 {
58 _PageCount = value;
59 ViewState["PageCount"] = _PageCount;
60 }
61 }
62
63 [Bindable(true)]
64 [Category("Appearance")]
65 [DefaultValue("")]
66 [Localizable(true)]
67 public string RecordCount
68 {
69 get
70 {
71 _RecordCount = (string)ViewState["RecordCount"];
72 return ((_RecordCount == null) ? "0" : _RecordCount);
73 }
74
75 set
76 {
77 _RecordCount = value;
78 ViewState["RecordCount"] = _RecordCount;
79 }
80 }
81
82 private string _StateCss;
83 [Bindable(true)]
84 [Category("Appearance")]
85 [DefaultValue("")]
86 [Localizable(true)]
87 public string StateCss
88 {
89 get
90 {
91 _StateCss = (string)ViewState["StateCss"];
92 return ((_StateCss == null) ? string.Empty : _StateCss);
93 }
94
95 set
96 {
97 _StateCss = value;
98 ViewState["StateCss"] = _StateCss;
99 }
100 }
101
102 private string _ButtonCss;
103 [Bindable(true)]
104 [Category("Appearance")]
105 [DefaultValue("")]
106 [Localizable(true)]
107 public string ButtonCss
108 {
109 get
110 {
111 _ButtonCss = (string)ViewState["ButtonCss"];
112 return ((_ButtonCss == null) ? string.Empty : _ButtonCss);
113 }
114
115 set
116 {
117 _ButtonCss = value;
118 ViewState["ButtonCss"] = _ButtonCss;
119 }
120 }
121
122 private string _txtCss;
123 [Bindable(true)]
124 [Category("Appearance")]
125 [DefaultValue("")]
126 [Localizable(true)]
127 public string TxtCss
128 {
129 get
130 {
131 _txtCss = (string)ViewState["TxtCss"];
132 return ((_txtCss == null) ? string.Empty : _txtCss);
133 }
134
135 set
136 {
137 _txtCss = value;
138 ViewState["TxtCss"] = _txtCss;
139 }
140 }
141
142 私有函数
194
195 go event
243
244 Last Event
271
272 Next Event
300
301 Prvi Event
326
327 Frist Evetn
347
348 protected override void CreateChildControls()
349 {
350 _btnFirst = new Button();
351 _btnFirst.ID = "btnFirst";
352 _btnFirst.Text = "9";
353 _btnFirst.Enabled = false;
354 _btnFirst.CssClass = this.ButtonCss;
355 _btnFirst.Click += new EventHandler(_btnFirst_Click);
356 this.Controls.Add(_btnFirst);
357
358 _btnPrvi = new Button();
359 _btnPrvi.ID = "btnPrvi";
360 _btnPrvi.Text = "3";
361 _btnPrvi.Enabled = false;
362 _btnPrvi.CssClass = this.ButtonCss;
363 _btnPrvi.Click += new EventHandler(_btnPrvi_Click);
364 this.Controls.Add(_btnPrvi);
365
366 _btnNext = new Button();
367 _btnNext.ID = "btnNext";
368 _btnNext.Text = "4";
369 _btnNext.CssClass = this.ButtonCss;
370 _btnNext.Click += new EventHandler(_btnNext_Click);
371 this.Controls.Add(_btnNext);
372
373 _btnLast = new Button();
374 _btnLast.ID = "btnLast";
375 _btnLast.Text = ":";
376 _btnLast.CssClass = this.ButtonCss;
377 _btnLast.Click += new EventHandler(_btnLast_Click);
378 this.Controls.Add(_btnLast);
379
380 txtPage = new TextBox();
381 txtPage.ID = "txtPage";
382 txtPage.CssClass = this.TxtCss;
383 txtPage.Width = new Unit(20);
384 this.Controls.Add(txtPage);
385
386 _btnGo = new Button();
387 _btnGo.ID = "btnGo";
388 _btnGo.Text = "2";
389 _btnGo.CssClass = this.ButtonCss;
390 _btnGo.Click += new EventHandler(_btnGo_Click);
391 this.Controls.Add(_btnGo);
392
393 _txtCurrentPage = new TextBox();
394 _txtCurrentPage.ID = "txtCurrentPage";
395 _txtCurrentPage.Text = "0";
396 _txtCurrentPage.Visible = false;
397 this.Controls.Add(_txtCurrentPage);
398 }
399
400 protected override void Render(HtmlTextWriter output)
401 {
402 int TotalPage = Int32.Parse(RecordCount) / Int32.Parse(PageCount);
403 if (Int32.Parse(RecordCount) % Int32.Parse(PageCount) > 0)
404 TotalPage += 1;
405 output.Write("<table><tr><td class = '"+ this.StateCss +"'>页码:" + (Int32.Parse(_txtCurrentPage.Text) + 1) + "/" + TotalPage + ",共" + RecordCount + "条</td><td class='"+ this.ButtonCss +"'><font face='webdings'>");
406 _btnFirst.RenderControl(output);
407 _btnPrvi.RenderControl(output);
408 _btnNext.RenderControl(output);
409 _btnLast.RenderBeginTag(output);
410 txtPage.RenderControl(output);
411 _btnGo.RenderControl(output);
412 _txtCurrentPage.RenderControl(output);
413 output.Write("</font></td></tr></table>");
414 }
415 }
416
417 public class PagerEventArgs
418 {
419 private int _CurrentPage;
420
421 public int CurrentPage
422 {
423 get { return _CurrentPage; }
424 set { _CurrentPage = value; }
425 }
426 }
427}
428
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Text;
5using System.Web;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8
9namespace CustomerControl
10{
11 [DefaultProperty("Text")]
12 [ToolboxData("<{0}:Pager runat=server></{0}:Pager>")]
13 public class Pager : WebControl,INamingContainer
14 {
15 public event PagerHander First;
16 public event PagerHander Prvi;
17 public event PagerHander Next;
18 public event PagerHander Last;
19 public event PagerHander Go;
20
21 public delegate void PagerHander(object sender, PagerEventArgs e);
22
23 //下一页
24 private Button _btnNext;
25 //上一页
26 private Button _btnPrvi;
27 //页码
28 private TextBox txtPage;
29 //到达页码
30 private Button _btnGo;
31 //最后一页
32 private Button _btnLast;
33 //第一页
34 private Button _btnFirst;
35 //当前页
36 private TextBox _txtCurrentPage;
37 //每页的条数
38 private string _PageCount = "10";
39 //总条数
40 private string _RecordCount;
41
42
43
44 [Bindable(true)]
45 [Category("Appearance")]
46 [DefaultValue("10")]
47 [Localizable(true)]
48 public string PageCount
49 {
50 get
51 {
52 _PageCount = (string)ViewState["PageCount"];
53 return ((_PageCount == null) ? "10" : _PageCount);
54 }
55
56 set
57 {
58 _PageCount = value;
59 ViewState["PageCount"] = _PageCount;
60 }
61 }
62
63 [Bindable(true)]
64 [Category("Appearance")]
65 [DefaultValue("")]
66 [Localizable(true)]
67 public string RecordCount
68 {
69 get
70 {
71 _RecordCount = (string)ViewState["RecordCount"];
72 return ((_RecordCount == null) ? "0" : _RecordCount);
73 }
74
75 set
76 {
77 _RecordCount = value;
78 ViewState["RecordCount"] = _RecordCount;
79 }
80 }
81
82 private string _StateCss;
83 [Bindable(true)]
84 [Category("Appearance")]
85 [DefaultValue("")]
86 [Localizable(true)]
87 public string StateCss
88 {
89 get
90 {
91 _StateCss = (string)ViewState["StateCss"];
92 return ((_StateCss == null) ? string.Empty : _StateCss);
93 }
94
95 set
96 {
97 _StateCss = value;
98 ViewState["StateCss"] = _StateCss;
99 }
100 }
101
102 private string _ButtonCss;
103 [Bindable(true)]
104 [Category("Appearance")]
105 [DefaultValue("")]
106 [Localizable(true)]
107 public string ButtonCss
108 {
109 get
110 {
111 _ButtonCss = (string)ViewState["ButtonCss"];
112 return ((_ButtonCss == null) ? string.Empty : _ButtonCss);
113 }
114
115 set
116 {
117 _ButtonCss = value;
118 ViewState["ButtonCss"] = _ButtonCss;
119 }
120 }
121
122 private string _txtCss;
123 [Bindable(true)]
124 [Category("Appearance")]
125 [DefaultValue("")]
126 [Localizable(true)]
127 public string TxtCss
128 {
129 get
130 {
131 _txtCss = (string)ViewState["TxtCss"];
132 return ((_txtCss == null) ? string.Empty : _txtCss);
133 }
134
135 set
136 {
137 _txtCss = value;
138 ViewState["TxtCss"] = _txtCss;
139 }
140 }
141
142 私有函数
194
195 go event
243
244 Last Event
271
272 Next Event
300
301 Prvi Event
326
327 Frist Evetn
347
348 protected override void CreateChildControls()
349 {
350 _btnFirst = new Button();
351 _btnFirst.ID = "btnFirst";
352 _btnFirst.Text = "9";
353 _btnFirst.Enabled = false;
354 _btnFirst.CssClass = this.ButtonCss;
355 _btnFirst.Click += new EventHandler(_btnFirst_Click);
356 this.Controls.Add(_btnFirst);
357
358 _btnPrvi = new Button();
359 _btnPrvi.ID = "btnPrvi";
360 _btnPrvi.Text = "3";
361 _btnPrvi.Enabled = false;
362 _btnPrvi.CssClass = this.ButtonCss;
363 _btnPrvi.Click += new EventHandler(_btnPrvi_Click);
364 this.Controls.Add(_btnPrvi);
365
366 _btnNext = new Button();
367 _btnNext.ID = "btnNext";
368 _btnNext.Text = "4";
369 _btnNext.CssClass = this.ButtonCss;
370 _btnNext.Click += new EventHandler(_btnNext_Click);
371 this.Controls.Add(_btnNext);
372
373 _btnLast = new Button();
374 _btnLast.ID = "btnLast";
375 _btnLast.Text = ":";
376 _btnLast.CssClass = this.ButtonCss;
377 _btnLast.Click += new EventHandler(_btnLast_Click);
378 this.Controls.Add(_btnLast);
379
380 txtPage = new TextBox();
381 txtPage.ID = "txtPage";
382 txtPage.CssClass = this.TxtCss;
383 txtPage.Width = new Unit(20);
384 this.Controls.Add(txtPage);
385
386 _btnGo = new Button();
387 _btnGo.ID = "btnGo";
388 _btnGo.Text = "2";
389 _btnGo.CssClass = this.ButtonCss;
390 _btnGo.Click += new EventHandler(_btnGo_Click);
391 this.Controls.Add(_btnGo);
392
393 _txtCurrentPage = new TextBox();
394 _txtCurrentPage.ID = "txtCurrentPage";
395 _txtCurrentPage.Text = "0";
396 _txtCurrentPage.Visible = false;
397 this.Controls.Add(_txtCurrentPage);
398 }
399
400 protected override void Render(HtmlTextWriter output)
401 {
402 int TotalPage = Int32.Parse(RecordCount) / Int32.Parse(PageCount);
403 if (Int32.Parse(RecordCount) % Int32.Parse(PageCount) > 0)
404 TotalPage += 1;
405 output.Write("<table><tr><td class = '"+ this.StateCss +"'>页码:" + (Int32.Parse(_txtCurrentPage.Text) + 1) + "/" + TotalPage + ",共" + RecordCount + "条</td><td class='"+ this.ButtonCss +"'><font face='webdings'>");
406 _btnFirst.RenderControl(output);
407 _btnPrvi.RenderControl(output);
408 _btnNext.RenderControl(output);
409 _btnLast.RenderBeginTag(output);
410 txtPage.RenderControl(output);
411 _btnGo.RenderControl(output);
412 _txtCurrentPage.RenderControl(output);
413 output.Write("</font></td></tr></table>");
414 }
415 }
416
417 public class PagerEventArgs
418 {
419 private int _CurrentPage;
420
421 public int CurrentPage
422 {
423 get { return _CurrentPage; }
424 set { _CurrentPage = value; }
425 }
426 }
427}
428