3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Namespace : System.Web.UI.MobileControls
25 * Class : PagedControl
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
33 using System
.Web
.Mobile
;
35 namespace System
.Web
.UI
.MobileControls
37 public abstract class PagedControl
: MobileControl
39 private static readonly object LoadItemsEvent
= new object();
41 private int itemCount
= 0;
42 private ItemPager itemPager
;
43 private bool pagingCharsChanged
= false;
45 protected PagedControl()
49 public event LoadItemsEventHandler LoadItems
53 Events
.AddHandler(LoadItemsEvent
, value);
57 Events
.RemoveHandler(LoadItemsEvent
, value);
61 private int PagerItemIndex
65 return (itemPager
== null ? 0 : itemPager
.ItemIndex
);
69 private int PagerItemCount
73 return (itemPager
== null ? InternalItemCount
:
78 protected abstract int InternalItemCount { get; }
80 public int FirstVisibleItemIndex
84 if(!IsCustomPaging
&& EnablePagination
)
85 return PagerItemIndex
;
90 private bool IsCustomPaging
94 return (itemCount
> 0);
110 public int ItemWeight
114 return ControlPager
.DefaultWeight
;
118 public int ItemsPerPage
122 object o
= ViewState
["ItemsPerPage"];
129 ViewState
["ItemsPerPage"] = value;
133 public int VisibleItemCount
137 if(IsCustomPaging
|| !EnablePagination
)
138 return InternalItemCount
;
139 return PagerItemCount
;
143 public override int VisibleWeight
147 if(VisibleItemCount
== -1)
149 return VisibleItemCount
* GetItemWeight();
153 private int GetItemWeight()
155 int iw
= Adapter
.ItemWeight
;
156 if(iw
== ControlPager
.UseDefaultWeight
)
161 protected virtual void OnLoadItems(LoadItemsEventArgs e
)
163 LoadItemsEventHandler lieh
= (LoadItemsEventHandler
)(Events
[LoadItemsEvent
]);
168 private void OnLoadItems()
170 OnLoadItems(new LoadItemsEventArgs(PagerItemIndex
, PagerItemCount
));
173 protected override void OnPageChange(int oldPageIndex
, int newPageIndex
)
175 pagingCharsChanged
= true;
178 protected override void OnPreRender(EventArgs e
)
182 if(!Page
.IsPostBack
|| Form
.PaginationStateChanged
183 || pagingCharsChanged
|| !IsViewStateEnabled())
191 private bool IsViewStateEnabled()
194 while(ctrl
!= null && ctrl
.EnableViewState
)
198 return (ctrl
== null);
201 public override void PaginateRecursive(ControlPager pager
)
205 if(IsCustomPaging
|| InternalItemCount
== 0)
208 itemPager
= pager
.GetItemPager(this, ic
, ipp
, GetItemWeight());