2009-10-30 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataGrid.cs
1 //
2 // System.Web.UI.WebControls.DataGrid.cs
3 //
4 // Authors:
5 //      Jackson Harper (jackson@ximian.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Web.Util;
31 using System.Collections;
32 using System.Globalization;
33 using System.ComponentModel;
34 using System.Reflection;
35 using System.Security.Permissions;
36
37 namespace System.Web.UI.WebControls {
38
39         // CAS
40         [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41         [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         // attributes
43         [Editor("System.Web.UI.Design.WebControls.DataGridComponentEditor, " + Consts.AssemblySystem_Design, typeof(System.ComponentModel.ComponentEditor))]
44         [Designer("System.Web.UI.Design.WebControls.DataGridDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45         public class DataGrid : BaseDataList, INamingContainer {
46
47                 public const string CancelCommandName = "Cancel";
48                 public const string DeleteCommandName = "Delete";
49                 public const string EditCommandName = "Edit";
50                 public const string SelectCommandName = "Select";
51                 public const string SortCommandName = "Sort";
52                 public const string UpdateCommandName = "Update";
53
54                 public const string PageCommandName = "Page";
55                 public const string NextPageCommandArgument = "Next";
56                 public const string PrevPageCommandArgument = "Prev";
57
58                 static readonly object CancelCommandEvent = new object ();
59                 static readonly object DeleteCommandEvent = new object ();
60                 static readonly object EditCommandEvent = new object ();
61                 static readonly object ItemCommandEvent = new object ();
62                 static readonly object ItemCreatedEvent = new object ();
63                 static readonly object ItemDataBoundEvent = new object ();
64                 static readonly object PageIndexChangedEvent = new object ();
65                 static readonly object SortCommandEvent = new object ();
66                 static readonly object UpdateCommandEvent = new object ();
67
68                 TableItemStyle alt_item_style;
69                 TableItemStyle edit_item_style;
70                 TableItemStyle footer_style;
71                 TableItemStyle header_style;
72                 TableItemStyle item_style;
73                 TableItemStyle selected_style;
74                 DataGridPagerStyle pager_style;
75                 
76                 ArrayList items_list;
77                 DataGridItemCollection items;
78
79                 ArrayList columns_list;
80                 DataGridColumnCollection columns;
81
82                 ArrayList data_source_columns_list;
83                 DataGridColumnCollection data_source_columns;
84
85                 Table render_table;
86                 DataGridColumn [] render_columns;
87                 PagedDataSource paged_data_source;
88                 IEnumerator data_enumerator;
89                 
90                 [DefaultValue(false)]
91                 [WebSysDescription ("")]
92                 [WebCategory ("Paging")]
93                 public virtual bool AllowCustomPaging {
94                         get { return ViewState.GetBool ("AllowCustomPaging", false); }
95                         set { ViewState ["AllowCustomPaging"] = value; }
96                 }
97
98                 [DefaultValue(false)]
99                 [WebSysDescription ("")]
100                 [WebCategory ("Paging")]
101                 public virtual bool AllowPaging {
102                         get { return ViewState.GetBool ("AllowPaging", false); }
103                         set { ViewState ["AllowPaging"] = value; }
104                 }
105
106                 [DefaultValue(false)]
107                 [WebSysDescription ("")]
108                 [WebCategory ("Behavior")]
109                 public virtual bool AllowSorting {
110                         get { return ViewState.GetBool ("AllowSorting", false); }
111                         set { ViewState ["AllowSorting"] = value; }
112                 }
113
114                 [DefaultValue(true)]
115                 [WebSysDescription ("")]
116                 [WebCategory ("Behavior")]
117                 public virtual bool AutoGenerateColumns {
118                         get { return ViewState.GetBool ("AutoGenerateColumns", true); }
119                         set { ViewState ["AutoGenerateColumns"] = value; }
120                 }
121
122 #if NET_2_0
123                 [UrlProperty]
124 #else
125                 [Bindable(true)]
126 #endif
127                 [DefaultValue("")]
128                 [Editor("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
129                 [WebSysDescription ("")]
130                 [WebCategory ("Appearance")]
131                 public virtual string BackImageUrl {
132                         get { return TableStyle.BackImageUrl; }
133                         set { TableStyle.BackImageUrl = value; }
134                 }
135
136 #if ONLY_1_1
137                 [Bindable(true)]
138 #endif
139                 [Browsable(false)]
140                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
141                 [WebSysDescription ("")]
142                 [WebCategory ("Behavior")]
143                 public int CurrentPageIndex {
144                         get { return ViewState.GetInt ("CurrentPageIndex", 0); }
145                         set {
146                                 if (value < 0)
147                                         throw new ArgumentOutOfRangeException ("value");
148                                 ViewState ["CurrentPageIndex"] = value;
149                         }
150                 }
151
152                 [DefaultValue(-1)]
153                 [WebSysDescription ("")]
154                 [WebCategory ("Misc")]
155                 public virtual int EditItemIndex {
156                         get { return ViewState.GetInt ("EditItemIndex", -1); }
157                         set {
158                                 if (value < -1)
159                                         throw new ArgumentOutOfRangeException ("value");
160                                 ViewState ["EditItemIndex"] = value;
161                         }
162                 }
163
164                 [Browsable(false)]
165                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
166                 [WebSysDescription ("")]
167                 [WebCategory ("Style")]
168                 public int PageCount {
169                         get {
170                                 if (paged_data_source != null)
171                                         return paged_data_source.PageCount;
172
173                                 return ViewState.GetInt ("PageCount", 0);
174                         }
175                 }
176
177                 [DefaultValue(10)]
178                 [WebSysDescription ("")]
179                 [WebCategory ("Paging")]
180                 public virtual int PageSize {
181                         get { return ViewState.GetInt ("PageSize", 10); }
182                         set {
183                                 if (value < 1)
184                                         throw new ArgumentOutOfRangeException ("value");
185                                 ViewState ["PageSize"] = value;
186                         }
187                 }
188
189                 void AdjustItemTypes (int prev_select, int new_select)
190                 {
191                         if (items_list == null)
192                                 return; // nothing to select
193
194                         int count = items_list.Count;
195                         if (count == 0)
196                                 return; // nothing to select
197
198                         DataGridItem item;
199                         // Restore item type for the previously selected one.
200                         if (prev_select >= 0 && prev_select < count) {
201                                 item = (DataGridItem) items_list [prev_select];
202                                 
203                                 if (item.ItemType == ListItemType.EditItem) {
204                                         // nothing to do. This has priority.
205                                 } else if ((item.ItemIndex % 2) != 0) {
206                                         item.SetItemType (ListItemType.AlternatingItem);
207                                 } else {
208                                         item.SetItemType (ListItemType.Item);
209                                 }
210                         }
211
212                         if (new_select == -1 || new_select >= count)
213                                 return; // nothing to select
214
215                         item = (DataGridItem) items_list [new_select];
216                         if (item.ItemType != ListItemType.EditItem) // EditItem takes precedence
217                                 item.SetItemType (ListItemType.SelectedItem);
218                 }
219
220                 [Bindable(true)]
221                 [DefaultValue(-1)]
222                 [WebSysDescription ("")]
223                 [WebCategory ("Paging")]
224                 public virtual int SelectedIndex {
225                         get { return ViewState.GetInt ("SelectedIndex", -1); }
226                         set {
227                                 if (value < -1)
228                                         throw new ArgumentOutOfRangeException ("value");
229
230                                 int selected_index = ViewState.GetInt ("SelectedIndex", -1);
231                                 AdjustItemTypes (selected_index, value);
232                                 ViewState ["SelectedIndex"] = value;
233                         }
234                 }
235
236                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
237                 [NotifyParentProperty(true)]
238                 [PersistenceMode(PersistenceMode.InnerProperty)]
239                 [WebSysDescription ("")]
240                 [WebCategory ("Style")]
241                 public virtual TableItemStyle AlternatingItemStyle {
242                         get {
243                                 if (alt_item_style == null) {
244                                         alt_item_style = new TableItemStyle ();
245                                         if (IsTrackingViewState)
246                                                 alt_item_style.TrackViewState ();
247                                 }
248                                 return alt_item_style;
249                         }
250                 }
251
252                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
253                 [NotifyParentProperty(true)]
254                 [PersistenceMode(PersistenceMode.InnerProperty)]
255                 [WebSysDescription ("")]
256                 [WebCategory ("Style")]
257                 public virtual TableItemStyle EditItemStyle {
258                         get {
259                                 if (edit_item_style == null) {
260                                         edit_item_style = new TableItemStyle ();
261                                         if (IsTrackingViewState)
262                                                 edit_item_style.TrackViewState ();
263                                 }
264                                 return edit_item_style;
265                         }
266                 }
267
268                 [DefaultValue(null)]
269                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
270                 [NotifyParentProperty(true)]
271                 [PersistenceMode(PersistenceMode.InnerProperty)]
272                 [WebSysDescription ("")]
273                 [WebCategory ("Style")]
274                 public virtual TableItemStyle FooterStyle {
275                         get {
276                                 if (footer_style == null) {
277                                         footer_style = new TableItemStyle ();
278                                         if (IsTrackingViewState)
279                                                 footer_style.TrackViewState ();
280                                 }
281                                 return footer_style;
282                         }
283                 }
284
285                 [DefaultValue(null)]
286                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
287                 [NotifyParentProperty(true)]
288                 [PersistenceMode(PersistenceMode.InnerProperty)]
289                 [WebSysDescription ("")]
290                 [WebCategory ("Style")]
291                 public virtual TableItemStyle HeaderStyle {
292                         get {
293                                 if (header_style == null) {
294                                         header_style = new TableItemStyle ();
295                                         if (IsTrackingViewState)
296                                                 header_style.TrackViewState ();
297                                 }
298                                 return header_style;
299                         }
300                 }
301
302                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
303                 [NotifyParentProperty(true)]
304                 [PersistenceMode(PersistenceMode.InnerProperty)]
305                 [WebSysDescription ("")]
306                 [WebCategory ("Style")]
307                 public virtual TableItemStyle ItemStyle {
308                         get {
309                                 if (item_style == null) {
310                                         item_style = new TableItemStyle ();
311                                         if (IsTrackingViewState)
312                                                 item_style.TrackViewState ();
313                                 }
314                                 return item_style;
315                         }
316                 }
317
318                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
319                 [NotifyParentProperty(true)]
320                 [PersistenceMode(PersistenceMode.InnerProperty)]
321                 [WebSysDescription ("")]
322                 [WebCategory ("Style")]
323                 public virtual TableItemStyle SelectedItemStyle {
324                         get {
325                                 if (selected_style == null) {
326                                         selected_style = new TableItemStyle ();
327                                         if (IsTrackingViewState)
328                                                 selected_style.TrackViewState ();
329                                 }
330                                 return selected_style;
331                         }
332                 }
333
334                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
335                 [NotifyParentProperty(true)]
336                 [PersistenceMode(PersistenceMode.InnerProperty)]
337                 [WebSysDescription ("")]
338                 [WebCategory ("Style")]
339                 public virtual DataGridPagerStyle PagerStyle {
340                         get {
341                                 if (pager_style == null) {
342                                         pager_style = new DataGridPagerStyle ();
343                                         if (IsTrackingViewState)
344                                                 pager_style.TrackViewState ();
345                                 }
346                                 return pager_style;
347                         }
348                 }
349
350                 [Browsable(false)]
351                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
352                 [WebSysDescription ("")]
353                 [WebCategory ("Style")]
354                 public virtual DataGridItemCollection Items {
355                         get {
356                                 EnsureChildControls ();
357                                 if (items == null) {
358                                         if (items_list == null)
359                                                 items_list = new ArrayList ();
360                                         items = new DataGridItemCollection (items_list);
361                                 }
362                                 return items;
363                         }
364                 }
365
366                 [DefaultValue (null)]
367                 [Editor ("System.Web.UI.Design.WebControls.DataGridColumnCollectionEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
368                 [MergableProperty (false)]
369                 [PersistenceMode (PersistenceMode.InnerProperty)]
370                 [WebSysDescription ("")]
371                 [WebCategory ("Behavior")]
372                 public virtual DataGridColumnCollection Columns {
373                         get {
374                                 if (columns == null) {
375                                         columns_list = new ArrayList ();
376                                         columns = new DataGridColumnCollection (this, columns_list);
377                                         if (IsTrackingViewState) {
378                                                 IStateManager manager = (IStateManager) columns;
379                                                 manager.TrackViewState ();
380                                         }
381                                 }
382                                 return columns;
383                         }
384                 }
385
386                 DataGridColumnCollection DataSourceColumns {
387                         get {
388                                 if (data_source_columns == null) {
389                                         data_source_columns_list = new ArrayList ();
390                                         data_source_columns = new DataGridColumnCollection (this,
391                                                         data_source_columns_list);
392                                         if (IsTrackingViewState) {
393                                                 IStateManager manager = (IStateManager) data_source_columns;
394                                                 manager.TrackViewState ();
395                                         }
396                                 }
397                                 return data_source_columns;
398                         }
399                 }
400                 
401                 Table RenderTable {
402                         get {
403                                 if (render_table == null) {
404 #if ONLY_1_1
405                                         render_table = new TableID (this);
406 #else
407                                         render_table = new ChildTable (this);
408 #endif
409                                         render_table.AutoID = false;
410                                 }
411                                 return render_table;
412                         }
413                 }
414
415                 [Browsable(false)]
416                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
417                 [WebSysDescription ("")]
418                 [WebCategory ("Paging")]
419                 public virtual DataGridItem SelectedItem {
420                         get {
421                                 if (SelectedIndex == -1)
422                                         return null;
423                                 return Items [SelectedIndex];
424                         }
425                 }
426
427 #if ONLY_1_1
428                 [Bindable(true)]
429 #endif
430                 [DefaultValue(false)]
431                 [WebSysDescription ("")]
432                 [WebCategory ("Appearance")]
433                 public virtual bool ShowFooter {
434                         get { return ViewState.GetBool ("ShowFooter", false); }
435                         set { ViewState ["ShowFooter"] = value; }
436                 }
437
438 #if ONLY_1_1
439                 [Bindable(true)]
440 #endif
441                 [DefaultValue(true)]
442                 [WebSysDescription ("")]
443                 [WebCategory ("Appearance")]
444                 public virtual bool ShowHeader {
445                         get { return ViewState.GetBool ("ShowHeader", true); }
446                         set { ViewState ["ShowHeader"] = value; }
447                 }
448
449                 [Browsable(false)]
450                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
451                 [WebSysDescription ("")]
452                 [WebCategory ("Appearance")]
453                 public virtual int VirtualItemCount {
454                         get { return ViewState.GetInt ("VirtualItemCount", 0); }
455                         set {
456                                 if (value < 0)
457                                         throw new ArgumentOutOfRangeException ("value");
458                                 ViewState ["VirtualItemCount"] = value;
459                         }
460                 }
461
462 #if NET_2_0
463                 protected override HtmlTextWriterTag TagKey {
464                         get { return HtmlTextWriterTag.Table; }
465                 }
466 #endif
467
468                 TableStyle TableStyle {
469                         get { return (TableStyle) ControlStyle; }
470                 }
471
472                 static Type [] item_args = new Type [] {typeof (int) };
473                 void AddColumnsFromSource (PagedDataSource data_source)
474                 {
475                         PropertyDescriptorCollection props = null;
476                         Type ptype = null;
477                         bool no_items = false;
478
479                         // Use plain reflection for the Item property.
480                         // If we use TypeDescriptor, props will hold
481                         // all of the Type properties, which will be listed as columns
482                         Type ds_type = data_source.GetType ();
483                         PropertyInfo pinfo = ds_type.GetProperty ("Item", item_args);
484                         if (pinfo == null) {
485                                 IEnumerator items = (data_source.DataSource != null) ? data_source.GetEnumerator () : null;
486                                 if (items != null && items.MoveNext ()) {
487                                         object data = items.Current;
488                                         if ((data is ICustomTypeDescriptor) || (!IsBindableType(data.GetType())))
489                                                 props = TypeDescriptor.GetProperties (data);
490                                         else if (data != null)
491                                                 ptype = data.GetType ();
492                                         data_enumerator = items;
493                                 } else {
494                                         no_items = true;
495                                 }
496                         } else {
497                                 ptype = pinfo.PropertyType;
498                         }
499
500                         if (ptype != null) {
501                                 // Found the "Item" property
502                                 AddPropertyToColumns ();
503                         } else if (props != null) {
504                                 foreach (PropertyDescriptor pd in props)
505                                         AddPropertyToColumns (pd, false);
506                         } else if (!no_items) {
507                                 // This is not thrown for an empty ArrayList.
508                                 string msg = String.Format ("DataGrid '{0}' cannot autogenerate " +
509                                                         "columns from the given datasource. {1}", ID, ptype);
510                                 throw new HttpException (msg);
511                         }
512                 }
513
514                 protected virtual ArrayList CreateColumnSet (PagedDataSource dataSource, bool useDataSource)
515                 {
516                         ArrayList res = new ArrayList ();
517                         if (columns_list != null)
518                                 res.AddRange (columns_list);
519
520                         if (AutoGenerateColumns) {
521                                 if (useDataSource) {
522                                         data_enumerator = null;
523                                         PropertyDescriptorCollection props = dataSource.GetItemProperties (null);
524                                         DataSourceColumns.Clear ();
525                                         if (props != null) {
526                                                 foreach (PropertyDescriptor d in props)
527                                                         AddPropertyToColumns (d, false);
528                                         } else {
529                                                 AddColumnsFromSource (dataSource);
530                                         }
531                                 }
532
533                                 if (data_source_columns != null && data_source_columns.Count > 0)
534                                         res.AddRange (data_source_columns);
535                         }
536
537                         return res;
538                 }
539
540                 void AddPropertyToColumns ()
541                 {
542                         BoundColumn b = new BoundColumn ();
543                         if (IsTrackingViewState) {
544                                 IStateManager m = (IStateManager) b;
545                                 m.TrackViewState ();
546                         }
547                         b.Set_Owner (this);
548                         b.HeaderText = "Item";
549                         b.SortExpression = "Item";
550                         b.DataField  = BoundColumn.thisExpr;
551                         DataSourceColumns.Add (b);
552                 }
553
554                 void AddPropertyToColumns (PropertyDescriptor prop, bool tothis)
555                 {
556                         BoundColumn b = new BoundColumn ();
557                         b.Set_Owner (this);
558                         if (IsTrackingViewState) {
559                                 IStateManager m = (IStateManager) b;
560                                 m.TrackViewState ();
561                         }
562                         b.HeaderText = prop.Name;
563                         b.DataField = (tothis ? BoundColumn.thisExpr : prop.Name);
564                         b.SortExpression = prop.Name;
565 #if NET_2_0
566                         if (string.Compare (DataKeyField, b.DataField, StringComparison.InvariantCultureIgnoreCase) == 0) {
567                                 b.ReadOnly = true;
568                         }
569 #endif
570                         DataSourceColumns.Add (b);
571                 }
572
573                 protected override void TrackViewState ()
574                 {
575                         base.TrackViewState ();
576
577                         if (pager_style != null)
578                                 pager_style.TrackViewState ();
579                         if (header_style != null)
580                                 header_style.TrackViewState ();
581                         if (footer_style != null)
582                                 footer_style.TrackViewState ();
583                         if (item_style != null)
584                                 item_style.TrackViewState ();
585                         if (alt_item_style != null)
586                                 alt_item_style.TrackViewState ();
587                         if (selected_style != null)
588                                 selected_style.TrackViewState ();
589                         if (edit_item_style != null)
590                                 edit_item_style.TrackViewState ();
591 #if NET_2_0
592                         if (ControlStyleCreated)
593                                 ControlStyle.TrackViewState ();
594 #endif
595                         IStateManager manager = (IStateManager) columns;
596                         if (manager != null)
597                                 manager.TrackViewState ();
598                 }
599
600                 protected override object SaveViewState ()
601                 {
602 #if NET_2_0
603                         object [] res = new object [11];
604 #else
605                         object [] res = new object [10];
606 #endif
607
608                         res [0] = base.SaveViewState ();
609                         if (columns != null) {
610                                 IStateManager cm = (IStateManager) columns;
611                                 res [1] = cm.SaveViewState ();
612                         }
613                         if (pager_style != null)
614                                 res [2] = pager_style.SaveViewState ();
615                         if (header_style != null)
616                                 res [3] = header_style.SaveViewState ();
617                         if (footer_style != null)
618                                 res [4] = footer_style.SaveViewState ();
619                         if (item_style != null)
620                                 res [5] = item_style.SaveViewState ();
621                         if (alt_item_style != null)
622                                 res [6] = alt_item_style.SaveViewState ();
623                         if (selected_style != null)
624                                 res [7] = selected_style.SaveViewState ();
625                         if (edit_item_style != null)
626                                 res [8] = edit_item_style.SaveViewState ();
627 #if NET_2_0
628                         if (ControlStyleCreated)
629                                 res [9] = ControlStyle.SaveViewState ();
630                         
631                         if (data_source_columns != null) {
632                                 IStateManager m = (IStateManager) data_source_columns;
633                                 res [10] = m.SaveViewState ();
634                         }
635 #else
636                         if (data_source_columns != null) {
637                                 IStateManager m = (IStateManager) data_source_columns;
638                                 res [9] = m.SaveViewState ();
639                         }
640 #endif
641
642                         return res;
643                 }
644
645                 protected override void LoadViewState (object savedState)
646                 {
647                         object [] pieces = savedState as object [];
648
649                         if (pieces == null)
650                                 return;
651
652                         base.LoadViewState (pieces [0]);
653                         if (columns != null) {
654                                 IStateManager cm = (IStateManager) columns;
655                                 cm.LoadViewState (pieces [1]);
656                         }
657                         if (pieces [2] != null)
658                                 PagerStyle.LoadViewState (pieces [2]);
659                         if (pieces [3] != null)
660                                 HeaderStyle.LoadViewState (pieces [3]);
661                         if (pieces [4] != null)
662                                 FooterStyle.LoadViewState (pieces [4]);
663                         if (pieces [5] != null)
664                                 ItemStyle.LoadViewState (pieces [5]);
665                         if (pieces [6] != null)
666                                 AlternatingItemStyle.LoadViewState (pieces [6]);
667                         if (pieces [7] != null)
668                                 SelectedItemStyle.LoadViewState (pieces [7]);
669                         if (pieces [8] != null)
670                                 EditItemStyle.LoadViewState (pieces [8]);
671
672 #if NET_2_0
673                         if (pieces [9] != null)
674                                 ControlStyle.LoadViewState (pieces [8]);
675
676                         if (pieces [10] != null) {
677                                 // IStateManager manager = (IStateManager) DataSourceColumns;
678                                 // manager.LoadViewState (pieces [10]);
679                                 object [] cols = (object []) pieces [10];
680                                 foreach (object o in cols) {
681                                         BoundColumn c = new BoundColumn ();
682                                         ((IStateManager) c).TrackViewState ();
683                                         c.Set_Owner (this);
684                                         ((IStateManager) c).LoadViewState (o);
685                                         DataSourceColumns.Add (c);
686                                 }
687                         }
688 #else
689                         if (pieces [9] != null) {
690                                 // IStateManager manager = (IStateManager) DataSourceColumns;
691                                 // manager.LoadViewState (pieces [9]);
692                                 object [] cols = (object []) pieces [9];
693                                 foreach (object o in cols) {
694                                         BoundColumn c = new BoundColumn ();
695                                         c.Set_Owner (this);
696                                         ((IStateManager) c).LoadViewState (o);
697                                         DataSourceColumns.Add (c);
698                                 }
699                         }
700 #endif
701                 }
702
703                 protected override Style CreateControlStyle ()
704                 {
705 #if NET_2_0
706                         TableStyle res = new TableStyle ();
707 #else
708                         TableStyle res = new TableStyle (ViewState);
709 #endif
710                         res.GridLines = GridLines.Both;
711                         res.CellSpacing = 0;
712                         return res;
713                 }
714
715                 protected virtual void InitializeItem (DataGridItem item, DataGridColumn [] columns)
716                 {
717                         bool th = UseAccessibleHeader && item.ItemType == ListItemType.Header;
718                         for (int i = 0; i < columns.Length; i++) {
719                                 TableCell cell = null;
720                                 if (th) {
721                                         cell = new TableHeaderCell ();
722                                         cell.Attributes["scope"] = "col";
723                                 }
724                                 else
725                                         cell = new TableCell ();
726                                 columns [i].InitializeCell (cell, i, item.ItemType);
727                                 item.Cells.Add (cell);
728                         }
729                 }
730
731                 protected virtual void InitializePager (DataGridItem item, int columnSpan, PagedDataSource pagedDataSource)
732                 {
733                         TableCell pager_cell;
734                         if (PagerStyle.Mode == PagerMode.NextPrev)
735                                 pager_cell = InitializeNextPrevPager (item, columnSpan, pagedDataSource);
736                         else
737                                 pager_cell = InitializeNumericPager (item, columnSpan, pagedDataSource);
738
739                         item.Controls.Add (pager_cell);
740                 }
741
742                 TableCell InitializeNumericPager (DataGridItem item, int columnSpan,
743                                 PagedDataSource paged)
744                 {
745                         TableCell res = new TableCell ();
746                         res.ColumnSpan = columnSpan;
747
748                         int button_count = PagerStyle.PageButtonCount;
749                         int current = paged.CurrentPageIndex;
750                         int start = current - (current % button_count);
751                         int end = start + button_count;
752
753                         if (end > paged.PageCount)
754                                 end = paged.PageCount;
755
756                         if (start > 0) {
757                                 LinkButton link = new LinkButton ();
758                                 link.Text = "...";
759                                 link.CommandName = PageCommandName;
760                                 link.CommandArgument = start.ToString (Helpers.InvariantCulture);
761                                 link.CausesValidation = false;
762                                 res.Controls.Add (link);
763                                 res.Controls.Add (new LiteralControl ("&nbsp;"));
764                         }
765
766                         for (int i = start; i < end; i++) {
767                                 Control number = null;
768                                 string page = (i + 1).ToString (Helpers.InvariantCulture);
769                                 if (i != paged.CurrentPageIndex) {
770                                         LinkButton link = new LinkButton ();
771                                         link.Text = page;
772                                         link.CommandName = PageCommandName;
773                                         link.CommandArgument = page;
774                                         link.CausesValidation = false;
775                                         number = link;
776                                 } else {
777                                         Label pageLabel = new Label();
778                                         pageLabel.Text = page;
779                                         number = pageLabel;
780                                 }
781
782                                 res.Controls.Add (number);
783                                 if (i < end - 1)
784                                         res.Controls.Add (new LiteralControl ("&nbsp;"));
785                         }
786
787                         if (end < paged.PageCount) {
788                                 res.Controls.Add (new LiteralControl ("&nbsp;"));
789                                 LinkButton link = new LinkButton ();
790                                 link.Text = "...";
791                                 link.CommandName = PageCommandName;
792                                 link.CommandArgument = (end + 1).ToString (Helpers.InvariantCulture);
793                                 link.CausesValidation = false;
794                                 res.Controls.Add (link);
795                         }
796
797                         return res;
798                 }
799
800                 TableCell InitializeNextPrevPager (DataGridItem item, int columnSpan, PagedDataSource paged)
801                 {
802                         TableCell res = new TableCell ();
803                         res.ColumnSpan = columnSpan;
804
805                         Control prev;
806                         Control next;
807
808                         if (paged.IsFirstPage) {
809                                 Label l = new Label ();
810                                 l.Text = PagerStyle.PrevPageText;
811                                 prev = l;
812                         } else {
813 #if NET_2_0
814                                 LinkButton l = new DataControlLinkButton ();
815 #else
816                                 LinkButton l = new LinkButton ();
817 #endif
818                                 l.Text = PagerStyle.PrevPageText;
819                                 l.CommandName = PageCommandName;
820                                 l.CommandArgument = PrevPageCommandArgument;
821                                 l.CausesValidation = false;
822                                 prev = l;
823                         }
824
825                         if (paged.Count > 0 && !paged.IsLastPage) {
826 #if NET_2_0
827                                 LinkButton l = new DataControlLinkButton ();
828 #else
829                                 LinkButton l = new LinkButton ();
830 #endif
831                                 l.Text = PagerStyle.NextPageText;
832                                 l.CommandName = PageCommandName;
833                                 l.CommandArgument = NextPageCommandArgument;
834                                 l.CausesValidation = false;
835                                 next = l;
836                         } else {
837                                 Label l = new Label ();
838                                 l.Text = PagerStyle.NextPageText;
839                                 next = l;
840                         }
841
842                         res.Controls.Add (prev);
843                         res.Controls.Add (new LiteralControl ("&nbsp;"));
844                         res.Controls.Add (next);
845
846                         return res;
847                 }
848                                 
849                 protected virtual DataGridItem CreateItem (int itemIndex, int dataSourceIndex,
850                                 ListItemType itemType)
851                 {
852                         DataGridItem res = new DataGridItem (itemIndex, dataSourceIndex, itemType);
853                         return res;
854                 }
855
856                 DataGridItem CreateItem (int item_index, int data_source_index,
857                                 ListItemType type, bool data_bind, object data_item,
858                                 PagedDataSource paged)
859                 {
860                         DataGridItem res = CreateItem (item_index, data_source_index, type);
861                         DataGridItemEventArgs args = new DataGridItemEventArgs (res);
862                         bool no_pager = (type != ListItemType.Pager);
863
864                         if (no_pager) {
865                                 InitializeItem (res, render_columns);
866                                 if (data_bind)
867                                         res.DataItem = data_item;
868                                 OnItemCreated (args);
869                         } else {
870                                 InitializePager (res, render_columns.Length, paged);
871                                 if (pager_style != null)
872                                         res.ApplyStyle (pager_style);
873                                 OnItemCreated (args);
874                         }
875
876                         // Add before the column is bound, so that the
877                         // value is saved in the viewstate
878                         RenderTable.Controls.Add (res);
879
880                         if (no_pager && data_bind) {
881                                 res.DataBind ();
882                                 OnItemDataBound (args);
883                                 res.DataItem = null;
884                         }
885                         return res;
886                 }
887
888                 class NCollection : ICollection {
889                         int n;
890
891                         public NCollection (int n)
892                         {
893                                 this.n = n;
894                         }
895
896                         public IEnumerator GetEnumerator ()
897                         {
898                                 for (int i = 0; i < n; i++)
899                                         yield return i;
900                         }
901
902                         public int Count {
903                                 get { return n; }
904                         }
905
906                         public bool IsSynchronized {
907                                 get { return false; }
908                         }
909
910                         public object SyncRoot {
911                                 get { return this; }
912                         }
913
914                         public void CopyTo (Array array, int index)
915                         {
916                                 throw new NotImplementedException ("This should never be called");
917                         }
918                 }
919
920                 protected override void CreateControlHierarchy (bool useDataSource)
921                 {
922                         Controls.Clear ();
923                         RenderTable.Controls.Clear ();
924                         Controls.Add (RenderTable);
925                         
926                         IEnumerable data_source;
927                         ArrayList keys = null;
928                         if (useDataSource) {
929 #if NET_2_0
930                                 if (IsBoundUsingDataSourceID)
931                                         data_source = GetData ();
932                                 else
933 #endif
934                                 data_source = DataSourceResolver.ResolveDataSource (DataSource, DataMember);
935                                 if (data_source == null) {
936                                         Controls.Clear ();
937                                         return;
938                                 }
939                                 
940                                 keys = DataKeysArray;
941                                 keys.Clear ();
942                         } else {
943                                 int nitems = ViewState.GetInt ("Items", 0);
944                                 data_source = new NCollection (nitems);
945                         }
946
947                         paged_data_source = new PagedDataSource ();
948                         PagedDataSource pds = paged_data_source;
949                         pds.AllowPaging = AllowPaging;
950                         pds.AllowCustomPaging = AllowCustomPaging;
951                         pds.DataSource = data_source;
952                         pds.CurrentPageIndex = CurrentPageIndex;
953                         pds.PageSize = PageSize;
954                         pds.VirtualCount = VirtualItemCount;
955
956                         if ((pds.IsPagingEnabled) && (pds.PageCount < pds.CurrentPageIndex)) {
957                                 Controls.Clear ();
958                                 throw new HttpException ("Invalid DataGrid PageIndex");
959                         }
960                         
961                         ArrayList cList = CreateColumnSet (paged_data_source, useDataSource);
962                         if (cList.Count == 0) {
963                                 Controls.Clear ();
964                                 return;
965                         }
966                         
967                         Page page = this.Page;
968                         if (page != null)
969                                 page.RequiresPostBackScript ();
970                         
971                         render_columns = new DataGridColumn [cList.Count];
972                         for (int c = 0; c < cList.Count; c++) {
973                                 DataGridColumn col = (DataGridColumn) cList [c];
974                                 col.Set_Owner (this);
975                                 col.Initialize ();
976                                 render_columns [c] = col;
977                         }
978
979                         if (pds.IsPagingEnabled)
980                                 CreateItem (-1, -1, ListItemType.Pager, false, null, pds);
981
982                         CreateItem (-1, -1, ListItemType.Header, useDataSource, null, pds);
983
984                         // No indexer on PagedDataSource so we have to do
985                         // this silly foreach and index++
986                         if (items_list == null)
987                                 items_list = new ArrayList ();
988                         else
989                                 items_list.Clear();
990
991                         bool skip_first = false;
992                         IEnumerator enumerator = null;
993                         if (data_enumerator != null) {
994                                 // replaced when creating bound columns
995                                 enumerator = data_enumerator;
996                                 skip_first = true;
997                         } else if (pds.DataSource != null) {
998                                 enumerator = pds.GetEnumerator ();
999                         } else {
1000                                 enumerator = null;
1001                         }
1002
1003                         int index = 0;
1004                         bool first = true;
1005                         string key = null;
1006                         int dataset_index = pds.FirstIndexInPage;
1007                         int selected_index = SelectedIndex;
1008                         int edit_item_index = EditItemIndex;
1009                         while (enumerator != null && (skip_first || enumerator.MoveNext ())) {
1010                                 // MS does not render <table blah></table> on empty datasource.
1011                                 if (first) {
1012                                         first = false;
1013                                         key = DataKeyField;
1014                                         skip_first = false;
1015                                 }
1016                                 object data = enumerator.Current;
1017                                 // This will throw if the DataKeyField is not there. As on MS, this
1018                                 // will not be hit on an empty datasource.
1019                                 // The values stored here can be used in events so that you can
1020                                 // get, for example, the row that was clicked
1021                                 // (data.Rows.Find (ItemsGrid.DataKeys [e.Item.ItemIndex]))
1022                                 // BaseDataList will keep the array across postbacks.
1023                                 if (useDataSource && key != "")
1024                                         keys.Add (DataBinder.GetPropertyValue (data, key));
1025
1026                                 ListItemType type = ListItemType.Item;
1027                                 if (index == edit_item_index) 
1028                                         type = ListItemType.EditItem;
1029                                 else if (index == selected_index) 
1030                                         type = ListItemType.SelectedItem;
1031                                 else if (index % 2 != 0) 
1032                                         type = ListItemType.AlternatingItem;
1033
1034                                 items_list.Add (CreateItem (index, dataset_index, type, useDataSource, data, pds));
1035                                 index++;
1036                                 dataset_index++;
1037                         }
1038
1039                         CreateItem (-1, -1, ListItemType.Footer, useDataSource, null, paged_data_source);
1040                         if (pds.IsPagingEnabled) {
1041                                 CreateItem (-1, -1, ListItemType.Pager, false, null, paged_data_source);
1042                                 if (useDataSource)
1043                                         ViewState ["Items"] = pds.IsCustomPagingEnabled ? index : pds.DataSourceCount;
1044                         } else if (useDataSource) {
1045                                 ViewState ["Items"] = index;
1046                         }
1047                 }
1048
1049                 void ApplyColumnStyle (TableCellCollection cells, ListItemType type)
1050                 {
1051                         int ncells = Math.Min (cells.Count, render_columns.Length);
1052                         if (ncells <= 0)
1053                                 return;
1054
1055                         for (int i = 0; i < ncells; i++) {
1056                                 Style style = null;
1057                                 TableCell cell = cells [i];
1058                                 DataGridColumn column = render_columns [i];
1059                                 if (!column.Visible) {
1060                                         cell.Visible = false;
1061                                         continue;
1062                                 }
1063
1064                                 style = column.GetStyle (type);
1065                                 if (style != null)
1066                                         cell.MergeStyle (style);
1067                         }
1068                 }
1069
1070                 protected override void PrepareControlHierarchy ()
1071                 {
1072                         if (!HasControls () || Controls.Count == 0)
1073                                 return; // No one called CreateControlHierarchy() with DataSource != null
1074
1075                         Table rt = render_table;
1076                         rt.CopyBaseAttributes (this);
1077                         rt.ApplyStyle (ControlStyle);
1078
1079                         rt.Caption = Caption;
1080                         rt.CaptionAlign = CaptionAlign;
1081                         rt.Enabled = Enabled;
1082
1083                         bool top_pager = true;
1084                         foreach (DataGridItem item in rt.Rows) {
1085                                 
1086                                 switch (item.ItemType) {
1087                                 case ListItemType.Item:
1088                                         ApplyItemStyle (item);
1089                                         break;
1090                                 case ListItemType.AlternatingItem:
1091                                         ApplyItemStyle (item);
1092                                         break;
1093                                 case ListItemType.EditItem:
1094                                         item.MergeStyle (edit_item_style);
1095                                         ApplyItemStyle (item);
1096                                         ApplyColumnStyle (item.Cells, ListItemType.EditItem);
1097                                         break;
1098                                 case ListItemType.Footer:
1099                                         if (!ShowFooter) {
1100                                                 item.Visible = false;
1101                                                 break;
1102                                         }
1103                                         if (footer_style != null)
1104                                                 item.MergeStyle (footer_style);
1105                                         ApplyColumnStyle (item.Cells, ListItemType.Footer);
1106                                         break;
1107                                 case ListItemType.Header:
1108                                         if (!ShowHeader) {
1109                                                 item.Visible = false;
1110                                                 break;
1111                                         }
1112                                         if (header_style != null)
1113                                                 item.MergeStyle (header_style);
1114                                         ApplyColumnStyle (item.Cells, ListItemType.Header);
1115                                         break;
1116                                 case ListItemType.SelectedItem:
1117                                         item.MergeStyle (selected_style);
1118                                         ApplyItemStyle (item);
1119                                         ApplyColumnStyle (item.Cells, ListItemType.SelectedItem);
1120                                         break;
1121                                 case ListItemType.Separator:
1122                                         ApplyColumnStyle (item.Cells, ListItemType.Separator);
1123                                         break;
1124                                 case ListItemType.Pager:
1125                                         DataGridPagerStyle ps = PagerStyle;
1126                                         if (ps.Visible == false || !paged_data_source.IsPagingEnabled) {
1127                                                 item.Visible = false;
1128                                         } else {
1129                                                 if (top_pager)
1130                                                         item.Visible = (ps.Position != PagerPosition.Bottom);
1131                                                 else
1132                                                         item.Visible = (ps.Position != PagerPosition.Top);
1133                                                 top_pager = false;
1134                                         }
1135
1136                                         if (item.Visible)
1137                                                 item.MergeStyle (pager_style);
1138                                         break;
1139                                 }
1140                         }
1141                 }
1142
1143                 void ApplyItemStyle (DataGridItem item)
1144                 {
1145                         if (item.ItemIndex % 2 != 0)
1146                                 item.MergeStyle (alt_item_style);
1147
1148                         item.MergeStyle (item_style);
1149                         ApplyColumnStyle (item.Cells, ListItemType.Item);
1150                 }
1151
1152                 protected override bool OnBubbleEvent (object source, EventArgs e)
1153                 {
1154                         DataGridCommandEventArgs de = e as DataGridCommandEventArgs;
1155
1156                         if (de == null)
1157                                 return false;
1158
1159                         string cn = de.CommandName;
1160                         CultureInfo inv = Helpers.InvariantCulture;
1161
1162                         OnItemCommand (de);
1163                         if (String.Compare (cn, CancelCommandName, true, inv) == 0) {
1164                                 OnCancelCommand (de);
1165                         } else if (String.Compare (cn, DeleteCommandName, true, inv) == 0) {
1166                                 OnDeleteCommand (de);
1167                         } else if (String.Compare (cn, EditCommandName, true, inv) == 0) {
1168                                 OnEditCommand (de);
1169                         } else if (String.Compare (cn, SelectCommandName, true, inv) == 0) {
1170                                 SelectedIndex = de.Item.ItemIndex;
1171                                 OnSelectedIndexChanged (de);
1172                         } else if (String.Compare (cn, SortCommandName, true, inv) == 0) {
1173                                 DataGridSortCommandEventArgs se = new DataGridSortCommandEventArgs (de.CommandSource, de);
1174                                 OnSortCommand (se);
1175                         } else if (String.Compare (cn, UpdateCommandName, true, inv) == 0) {
1176                                 OnUpdateCommand (de);
1177                         } else if (String.Compare (cn, PageCommandName, true, inv) == 0) {
1178                                 int new_index;
1179                                 if (String.Compare ((string) de.CommandArgument,
1180                                                     NextPageCommandArgument, true, inv) == 0) {
1181                                         new_index = CurrentPageIndex + 1;
1182                                 } else if (String.Compare ((string) de.CommandArgument,
1183                                                            PrevPageCommandArgument, true, inv) == 0) {
1184                                         new_index = CurrentPageIndex - 1;
1185                                 } else {
1186                                         // It seems to just assume it's an int and parses, no
1187                                         // checks to make sure its valid or anything.
1188                                         //  also it's always one less then specified, not sure
1189                                         // why that is.
1190                                         new_index = Int32.Parse ((string) de.CommandArgument, inv) - 1;
1191                                 }
1192                                 DataGridPageChangedEventArgs pc = new DataGridPageChangedEventArgs (
1193                                         de.CommandSource, new_index);
1194                                 OnPageIndexChanged (pc);
1195                         }
1196
1197                         return true;
1198                 }
1199
1200                 protected virtual void OnCancelCommand (DataGridCommandEventArgs e)
1201                 {
1202                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [CancelCommandEvent];
1203                         if (handler != null)
1204                                 handler (this, e);
1205                 }
1206
1207                 protected virtual void OnDeleteCommand (DataGridCommandEventArgs e)
1208                 {
1209                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [DeleteCommandEvent];
1210                         if (handler != null)
1211                                 handler (this, e);
1212                 }
1213
1214                 protected virtual void OnEditCommand (DataGridCommandEventArgs e)
1215                 {
1216                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [EditCommandEvent];
1217                         if (handler != null)
1218                                 handler (this, e);
1219                 }
1220
1221                 protected virtual void OnItemCommand (DataGridCommandEventArgs e)
1222                 {
1223                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [ItemCommandEvent];
1224                         if (handler != null)
1225                                 handler (this, e);
1226                 }
1227
1228                 protected virtual void OnItemCreated (DataGridItemEventArgs e)
1229                 {
1230                         DataGridItemEventHandler handler = (DataGridItemEventHandler) Events [ItemCreatedEvent];
1231                         if (handler != null)
1232                                 handler (this, e);
1233                 }
1234
1235                 protected virtual void OnItemDataBound (DataGridItemEventArgs e)
1236                 {
1237                         DataGridItemEventHandler handler = (DataGridItemEventHandler) Events [ItemDataBoundEvent];
1238                         if (handler != null)
1239                                 handler (this, e);
1240                 }
1241
1242                 protected virtual void OnPageIndexChanged (DataGridPageChangedEventArgs e)
1243                 {
1244                         DataGridPageChangedEventHandler handler = (DataGridPageChangedEventHandler) Events [PageIndexChangedEvent];
1245                         if (handler != null)
1246                                 handler (this, e);
1247                 }
1248
1249                 protected virtual void OnSortCommand (DataGridSortCommandEventArgs e)
1250                 {
1251                         DataGridSortCommandEventHandler handler = (DataGridSortCommandEventHandler) Events [SortCommandEvent];
1252                         if (handler != null)
1253                                 handler (this, e);
1254                 }
1255
1256                 protected virtual void OnUpdateCommand (DataGridCommandEventArgs e)
1257                 {
1258                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [UpdateCommandEvent];
1259                         if (handler != null)
1260                                 handler (this, e);
1261                 }
1262
1263                 [WebSysDescription ("")]
1264                 [WebCategory ("Action")]
1265                 public event DataGridCommandEventHandler CancelCommand {
1266                         add { Events.AddHandler (CancelCommandEvent, value); }
1267                         remove { Events.RemoveHandler (CancelCommandEvent, value); }
1268                 }
1269
1270                 [WebSysDescription ("")]
1271                 [WebCategory ("Action")]
1272                 public event DataGridCommandEventHandler DeleteCommand {
1273                         add { Events.AddHandler (DeleteCommandEvent, value); }
1274                         remove { Events.RemoveHandler (DeleteCommandEvent, value); }
1275                 }
1276
1277                 [WebSysDescription ("")]
1278                 [WebCategory ("Action")]
1279                 public event DataGridCommandEventHandler EditCommand {
1280                         add { Events.AddHandler (EditCommandEvent, value); }
1281                         remove { Events.RemoveHandler (EditCommandEvent, value); }
1282                 }
1283
1284                 [WebSysDescription ("")]
1285                 [WebCategory ("Action")]
1286                 public event DataGridCommandEventHandler ItemCommand {
1287                         add { Events.AddHandler (ItemCommandEvent, value); }
1288                         remove { Events.RemoveHandler (ItemCommandEvent, value); }
1289                         
1290                 }
1291
1292                 [WebSysDescription ("")]
1293                 [WebCategory ("Action")]
1294                 public event DataGridItemEventHandler ItemCreated {
1295                         add { Events.AddHandler (ItemCreatedEvent, value); }
1296                         remove { Events.RemoveHandler (ItemCreatedEvent, value); }
1297                 }
1298
1299                 [WebSysDescription ("")]
1300                 [WebCategory ("Action")]
1301                 public event DataGridItemEventHandler ItemDataBound {
1302                         add { Events.AddHandler (ItemDataBoundEvent, value); }
1303                         remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
1304                 }
1305
1306                 [WebSysDescription ("")]
1307                 [WebCategory ("Action")]
1308                 public event DataGridPageChangedEventHandler PageIndexChanged {
1309                         add { Events.AddHandler (PageIndexChangedEvent, value); }
1310                         remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
1311                 }
1312
1313                 [WebSysDescription ("")]
1314                 [WebCategory ("Action")]
1315                 public event DataGridSortCommandEventHandler SortCommand {
1316                         add { Events.AddHandler (SortCommandEvent, value); }
1317                         remove { Events.RemoveHandler (SortCommandEvent, value); }
1318                 }
1319
1320                 [WebSysDescription ("")]
1321                 [WebCategory ("Action")]
1322                 public event DataGridCommandEventHandler UpdateCommand {
1323                         add { Events.AddHandler (UpdateCommandEvent, value); }
1324                         remove { Events.AddHandler (UpdateCommandEvent, value); }
1325                 }
1326         }
1327 }
1328
1329