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);
75 [DefaultValue (typeof (PagerMode), "NextPrev"), WebCategory ("Misc")]
76 [NotifyParentProperty (true)]
77 [WebSysDescription ("The mode used for displaying multiple pages.")]
84 return (PagerMode)ViewState["Mode"];
86 return PagerMode.NextPrev;
90 if(!Enum.IsDefined(typeof(PagerMode), value))
92 throw new ArgumentOutOfRangeException("value");
94 ViewState["Mode"] = value;
104 [DefaultValue (">"), WebCategory ("Misc")]
105 [NotifyParentProperty (true)]
106 [WebSysDescription ("The text for the 'next page' button.")]
107 public string NextPageText
111 if(IsSet(NEXT_PG_TEXT))
113 return (string)ViewState["NextPageText"];
119 ViewState["NextPageText"] = value;
129 [DefaultValue ("<"), WebCategory ("Misc")]
130 [NotifyParentProperty (true)]
131 [WebSysDescription ("The text for the 'previous page' button.")]
132 public string PrevPageText
136 if(IsSet(PREV_PG_TEXT))
138 return (string)ViewState["PrevPageText"];
144 ViewState["PrevPageText"] = value;
152 [DefaultValue (10), WebCategory ("Misc")]
153 [NotifyParentProperty (true)]
154 [WebSysDescription ("The maximum number of pages to show as direct links.")]
155 public int PageButtonCount
159 if(IsSet(PG_BTN_COUNT))
161 return (int)ViewState["PageButtonCount"];
168 throw new ArgumentOutOfRangeException("value");
170 ViewState["PageButtonCount"] = value;
178 [DefaultValue (typeof (PagerPosition), "Bottom"), WebCategory ("Misc")]
179 [NotifyParentProperty (true)]
180 [WebSysDescription ("The position for the page display.")]
181 public PagerPosition Position
187 return (PagerPosition)ViewState["Position"];
189 return PagerPosition.Bottom;
193 if(!Enum.IsDefined(typeof(PagerPosition), value))
195 throw new ArgumentException();
197 ViewState["Position"] = value;
207 [DefaultValue (true), WebCategory ("Misc")]
208 [NotifyParentProperty (true)]
209 [WebSysDescription ("Determines if paging functionallity is visible to the user.")]
216 return (bool)ViewState["PagerVisible"];
222 ViewState["PagerVisible"] = value;
224 owner.OnPagerChanged();
228 public override void CopyFrom(Style s)
230 if(s != null && !s.IsEmpty)
233 if(!(s is DataGridPagerStyle)) return;
235 DataGridPagerStyle from = (DataGridPagerStyle)s;
240 if(from.IsSet(NEXT_PG_TEXT))
242 NextPageText = from.NextPageText;
244 if(from.IsSet(PG_BTN_COUNT))
246 PageButtonCount = from.PageButtonCount;
248 if(from.IsSet(POSITION))
250 Position = from.Position;
252 if(from.IsSet(VISIBLE))
254 Visible = from.Visible;
256 if(from.IsSet(PREV_PG_TEXT))
258 PrevPageText = from.PrevPageText;
263 public override void MergeWith(Style s)
265 if(s != null && !s.IsEmpty)
275 if(!(s is DataGridPagerStyle)) return;
277 DataGridPagerStyle with = (DataGridPagerStyle)s;
278 if(with.IsSet(MODE) && !IsSet(MODE))
282 if(with.IsSet(NEXT_PG_TEXT) && !IsSet(NEXT_PG_TEXT))
284 NextPageText = with.NextPageText;
286 if(with.IsSet(PG_BTN_COUNT) && !IsSet(PG_BTN_COUNT))
288 PageButtonCount = with.PageButtonCount;
290 if(with.IsSet(POSITION) && !IsSet(POSITION))
292 Position = with.Position;
294 if(with.IsSet(VISIBLE) && !IsSet(VISIBLE))
296 Visible = with.Visible;
298 if(with.IsSet(PREV_PG_TEXT) && !IsSet(PREV_PG_TEXT))
300 PrevPageText = with.PrevPageText;
305 public override void Reset()
309 ViewState.Remove("Mode");
311 if(IsSet(NEXT_PG_TEXT))
313 ViewState.Remove("NextPageText");
315 if(IsSet(PG_BTN_COUNT))
317 ViewState.Remove("PageButtonCount");
321 ViewState.Remove("Position");
325 ViewState.Remove("PagerVisible");
327 if(IsSet(PREV_PG_TEXT))
329 ViewState.Remove("PrevPageText");