2 // System.Web.UI.WebControls.DataGridPagerStyle.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.ComponentModel;
38 namespace System.Web.UI.WebControls
40 public sealed class DataGridPagerStyle : TableItemStyle
44 private static int MODE = (0x01 << 19);
45 private static int NEXT_PG_TEXT = (0x01 << 20);
46 private static int PG_BTN_COUNT = (0x01 << 21);
47 private static int POSITION = (0x01 << 22);
48 private static int VISIBLE = (0x01 << 23);
49 private static int PREV_PG_TEXT = (0x01 << 24);
51 internal DataGridPagerStyle(DataGrid owner): base()
56 internal bool IsPagerOnTop
59 PagerPosition p = Position;
60 return (p == PagerPosition.Top || p == PagerPosition.TopAndBottom);
64 internal bool IsPagerOnBottom
67 PagerPosition p = Position;
68 return (p == PagerPosition.Bottom || p == PagerPosition.TopAndBottom);
72 [DefaultValue (typeof (PagerMode), "NextPrev"), Bindable (true), WebCategory ("Misc")]
73 [NotifyParentProperty (true)]
74 [WebSysDescription ("The mode used for displaying multiple pages.")]
81 return (PagerMode)ViewState["Mode"];
83 return PagerMode.NextPrev;
87 if(!Enum.IsDefined(typeof(PagerMode), value))
89 throw new ArgumentOutOfRangeException("value");
91 ViewState["Mode"] = value;
96 [DefaultValue (">"), Bindable (true), WebCategory ("Misc")]
97 [NotifyParentProperty (true)]
98 [WebSysDescription ("The text for the 'next page' button.")]
99 public string NextPageText
103 if(IsSet(NEXT_PG_TEXT))
105 return (string)ViewState["NextPageText"];
111 ViewState["NextPageText"] = value;
116 [DefaultValue ("<"), Bindable (true), WebCategory ("Misc")]
117 [NotifyParentProperty (true)]
118 [WebSysDescription ("The text for the 'previous page' button.")]
119 public string PrevPageText
123 if(IsSet(PREV_PG_TEXT))
125 return (string)ViewState["PrevPageText"];
131 ViewState["PrevPageText"] = value;
136 [DefaultValue (10), Bindable (true), WebCategory ("Misc")]
137 [NotifyParentProperty (true)]
138 [WebSysDescription ("The maximum number of pages to show as direct links.")]
139 public int PageButtonCount
143 if(IsSet(PG_BTN_COUNT))
145 return (int)ViewState["PageButtonCount"];
152 throw new ArgumentOutOfRangeException("value");
154 ViewState["PageButtonCount"] = value;
159 [DefaultValue (typeof (PagerPosition), "Bottom"), Bindable (true), WebCategory ("Misc")]
160 [NotifyParentProperty (true)]
161 [WebSysDescription ("The position for the page display.")]
162 public PagerPosition Position
168 return (PagerPosition)ViewState["Position"];
170 return PagerPosition.Bottom;
174 if(!Enum.IsDefined(typeof(PagerPosition), value))
176 throw new ArgumentException();
178 ViewState["Position"] = value;
183 [DefaultValue (true), Bindable (true), WebCategory ("Misc")]
184 [NotifyParentProperty (true)]
185 [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
192 return (bool)ViewState["PagerVisible"];
198 ViewState["PagerVisible"] = value;
200 owner.OnPagerChanged();
204 public override void CopyFrom(Style s)
206 if(s != null && !s.IsEmpty)
209 if(!(s is DataGridPagerStyle)) return;
211 DataGridPagerStyle from = (DataGridPagerStyle)s;
216 if(from.IsSet(NEXT_PG_TEXT))
218 NextPageText = from.NextPageText;
220 if(from.IsSet(PG_BTN_COUNT))
222 PageButtonCount = from.PageButtonCount;
224 if(from.IsSet(POSITION))
226 Position = from.Position;
228 if(from.IsSet(VISIBLE))
230 Visible = from.Visible;
232 if(from.IsSet(PREV_PG_TEXT))
234 PrevPageText = from.PrevPageText;
239 public override void MergeWith(Style s)
241 if(s != null && !s.IsEmpty)
251 if(!(s is DataGridPagerStyle)) return;
253 DataGridPagerStyle with = (DataGridPagerStyle)s;
254 if(with.IsSet(MODE) && !IsSet(MODE))
258 if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
260 NextPageText = with.NextPageText;
262 if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
264 PageButtonCount = with.PageButtonCount;
266 if(with.IsSet(POSITION) && !IsSet(POSITION))
268 Position = with.Position;
270 if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
272 Visible = with.Visible;
274 if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
276 PrevPageText = with.PrevPageText;
281 public override void Reset()
285 ViewState.Remove("Mode");
287 if(IsSet(NEXT_PG_TEXT))
289 ViewState.Remove("NextPageText");
291 if(IsSet(PG_BTN_COUNT))
293 ViewState.Remove("PageButtonCount");
297 ViewState.Remove("Position");
301 ViewState.Remove("PagerVisible");
303 if(IsSet(PREV_PG_TEXT))
305 ViewState.Remove("PrevPageText");