AspNetPager分页控件
AspNetPager源代码—PagerDesigner.cs
1 //AspNetPager分页控件源代码:
2 //版权所有:陕西省延安市吴起县博杨计算机有限公司 杨涛(Webdiyer)
3 //此源代码仅供学习参考,不得用于任何商业用途;
4 //您可以修改并重新编译该控件,但源代码中的版权信息必须原样保留!
5 //有关控件升级及新控件发布信息,请留意 www.webdiyer.com 。
6
7 using System;
8 using System.ComponentModel;
9 using System.ComponentModel.Design;
10 using System.Web.UI;
11 using System.IO;
12
13 namespace Wuqi.Webdiyer
14 {
15
16 #region AspNetPager Control Designer
17 /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Class[@name="PagerDesigner"]/*'/>
18 public class PagerDesigner : System.Web.UI.Design.ControlDesigner
19 {
20
21 private AspNetPager wb;
22
23 /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetEditableDesignerRegionContent"]/*'/>
24 public override string GetEditableDesignerRegionContent(System.Web.UI.Design.EditableDesignerRegion region)
25 {
26 region.Selectable = false;
27 return null;
28 }
29
30 /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetDesignTimeHtml"]/*'/>
31 public override string GetDesignTimeHtml()
32 {
33
34 wb = (AspNetPager)Component;
35 wb.RecordCount = 225;
36 StringWriter sw = new StringWriter();
37 HtmlTextWriter writer = new HtmlTextWriter(sw);
38 wb.RenderControl(writer);
39 return sw.ToString();
40 }
41
42 /// <include file='AspNetPagerDocs.xml' path='AspNetPagerDoc/Method[@name="GetErrorDesignTimeHtml"]/*'/>
43 protected override string GetErrorDesignTimeHtml(Exception e)
44 {
45 string errorstr = "Error creating control:" + e.Message;
46 return CreatePlaceHolderDesignTimeHtml(errorstr);
47 }
48
49 public override DesignerActionListCollection ActionLists
50 {
51 get
52 {
53 DesignerActionListCollection actionLists = new DesignerActionListCollection();
54 actionLists.Add(new AspNetPagerActionList(this.Component));
55 return actionLists;
56 }
57 }
58
59 }
60 /// <summary>
61 /// Designer Action List
62 /// </summary>
63 public class AspNetPagerActionList : DesignerActionList
64 {
65 private AspNetPager pager;
66 private DesignerActionUIService svc = null;
67 /// <summary>
68 /// Constructor
69 /// </summary>
70 /// <param name="component"></param>
71 public AspNetPagerActionList(IComponent component)
72 : base(component)
73 {
74 pager = component as AspNetPager;
75 svc = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
76 }
77
78 public override DesignerActionItemCollection GetSortedActionItems()
79 {
80 DesignerActionItemCollection actionItems = new DesignerActionItemCollection();
81 actionItems.Add(new DesignerActionHeaderItem("分页方式"));
82 actionItems.Add(new DesignerActionPropertyItem("UrlPaging", "启用Url分页", "分页"));
83
84 actionItems.Add(new DesignerActionHeaderItem("外观及文本"));
85 actionItems.Add(new DesignerActionPropertyItem("ShowFirstLast", "显示首页和尾页按钮", "外观"));
86 actionItems.Add(new DesignerActionPropertyItem("ShowPrevNext", "显示上一页和下一页按钮", "外观"));
87 actionItems.Add(new DesignerActionPropertyItem("CurrentPageButtonPosition", "当前页数字索引按钮的显示位置", "外观"));
88 actionItems.Add(new DesignerActionMethodItem(this, "SetPageIndexBox", "页索引文本或下拉框...", "外观", true));
89 actionItems.Add(new DesignerActionMethodItem(this, "SetNavText", "导航按钮显示文本...", "外观", true));
90 actionItems.Add(new DesignerActionMethodItem(this, "SetCustomInfoHTML", "自定义信息区显示方式及内容...", "外观", true));
91 actionItems.Add(new DesignerActionMethodItem(this, "ShowSPWindow", "分页存储过程生成工具...", "工具及帮助", true));
92 actionItems.Add(new DesignerActionMethodItem(this, "ShowAboutForm", "关于AspNetPager...", "工具及帮助", true));
93
94 return actionItems;
95 }
96
97 public bool UrlPaging
98 {
99 get
100 {
101 return pager.UrlPaging;
102 }
103 set
104 {
105 SetProperty("UrlPaging", value);
106 if (!value)
107 SetProperty("EnableUrlRewriting", false);
108 }
109 }
110
111 public bool ShowFirstLast
112 {
113 get
114 {
115 return pager.ShowFirstLast;
116 }
117 set
118 {
119 SetProperty("ShowFirstLast", value);
120 }
121 }
122
123 public bool ShowPrevNext
124 {
125 get
126 {
127 return pager.ShowPrevNext;
128 }
129 set
130 {
131 SetProperty("ShowPrevNext", value);
132 }
133 }
134
135 public PagingButtonPosition CurrentPageButtonPosition
136 {
137 get
138 {
139 return pager.CurrentPageButtonPosition;
140 }
141 set
142 {
143 SetProperty("CurrentPageButtonPosition", value);
144 }
145 }
146
147 public void SetNavText()
148 {
149 NavTextForm f = new NavTextForm(pager.FirstPageText, pager.LastPageText, pager.PrevPageText, pager.NextPageText);
150 if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
151 {
152 SetProperty("FirstPageText", f.FirstPageText);
153 SetProperty("LastPageText", f.LastPageText);
154 SetProperty("PrevPageText", f.PrevPageText);
155 SetProperty("NextPageText", f.NextPageText);
156 }
157 }
158
159 public void SetCustomInfoHTML()
160 {
161 CustomInfoForm f = new CustomInfoForm(pager.ShowCustomInfoSection,pager.CustomInfoHTML);
162 if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
163 {
164 SetProperty("ShowCustomInfoSection", f.ShowCustomSection);
165 SetProperty("CustomInfoHTML", f.CustomInfoHtml);
166 }
167 }
168
169 public void SetPageIndexBox()
170 {
171 PageIndexBoxForm f = new PageIndexBoxForm(pager.ShowPageIndexBox, pager.ShowBoxThreshold, pager.PageIndexBoxType,pager.TextBeforePageIndexBox,pager.TextAfterPageIndexBox,pager.SubmitButtonText);
172 if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
173 {
174 SetProperty("ShowPageIndexBox", f.ShowIndexBox);
175 SetProperty("ShowBoxThreshold", f.Threshold);
176 SetProperty("PageIndexBoxType", f.BoxType);
177 SetProperty("TextBeforePageIndexBox", f.TextBeforeBox);
178 SetProperty("TextAfterPageIndexBox", f.TextAfterBox);
179 SetProperty("SubmitButtonText", f.SubmitButtonText);
180 }
181 }
182
183 public void ShowSPWindow()
184 {
185 StoredProcForm f = new StoredProcForm();
186 f.ShowDialog();
187 }
188
189 public void ShowAboutForm()
190 {
191 AboutForm f = new AboutForm();
192 f.ShowDialog();
193 }
194
195 // Helper method to safely set a component’s property
196 private void SetProperty(string propertyName, object value)
197 {
198 // Get property
199 PropertyDescriptor property = TypeDescriptor.GetProperties(pager)[propertyName];
200 // Set property value
201 property.SetValue(pager, value);
202 }
203 }
204 #endregion
205 }
