fixed: when removed the names from the bag also removed FontStyles.Names flag from...
[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                 private static readonly object CancelCommandEvent = new object ();
59                 private static readonly object DeleteCommandEvent = new object ();
60                 private static readonly object EditCommandEvent = new object ();
61                 private static readonly object ItemCommandEvent = new object ();
62                 private static readonly object ItemCreatedEvent = new object ();
63                 private static readonly object ItemDataBoundEvent = new object ();
64                 private static readonly object PageIndexChangedEvent = new object ();
65                 private static readonly object SortCommandEvent = new object ();
66                 private static readonly object UpdateCommandEvent = new object ();
67
68                 private TableItemStyle alt_item_style;
69                 private TableItemStyle edit_item_style;
70                 private TableItemStyle footer_style;
71                 private TableItemStyle header_style;
72                 private TableItemStyle item_style;
73                 private TableItemStyle selected_style;
74                 private DataGridPagerStyle pager_style;
75                 
76                 private ArrayList items_list;
77                 private DataGridItemCollection items;
78
79                 private ArrayList columns_list;
80                 private DataGridColumnCollection columns;
81
82                 private ArrayList data_source_columns_list;
83                 private DataGridColumnCollection data_source_columns;
84
85                 private Table render_table;
86                 private DataGridColumn [] render_columns;
87                 private PagedDataSource paged_data_source;
88                 private 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                                 if (items == null) {
357                                         if (items_list == null)
358                                                 items_list = new ArrayList ();
359                                         items = new DataGridItemCollection (items_list);
360                                 }
361                                 return items;
362                         }
363                 }
364
365                 [DefaultValue (null)]
366                 [Editor ("System.Web.UI.Design.WebControls.DataGridColumnCollectionEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
367                 [MergableProperty (false)]
368                 [PersistenceMode (PersistenceMode.InnerProperty)]
369                 [WebSysDescription ("")]
370                 [WebCategory ("Behavior")]
371                 public virtual DataGridColumnCollection Columns {
372                         get {
373                                 if (columns == null) {
374                                         columns_list = new ArrayList ();
375                                         columns = new DataGridColumnCollection (this, columns_list);
376                                         if (IsTrackingViewState) {
377                                                 IStateManager manager = (IStateManager) columns;
378                                                 manager.TrackViewState ();
379                                         }
380                                 }
381                                 return columns;
382                         }
383                 }
384
385                 private DataGridColumnCollection DataSourceColumns {
386                         get {
387                                 if (data_source_columns == null) {
388                                         data_source_columns_list = new ArrayList ();
389                                         data_source_columns = new DataGridColumnCollection (this,
390                                                         data_source_columns_list);
391                                         if (IsTrackingViewState) {
392                                                 IStateManager manager = (IStateManager) data_source_columns;
393                                                 manager.TrackViewState ();
394                                         }
395                                 }
396                                 return data_source_columns;
397                         }
398                 }
399
400                 class TableID : Table {
401                         Control parent;
402
403                         public TableID (Control parent)
404                         {
405                                 this.parent = parent;
406                         }
407
408                         protected override void AddAttributesToRender (HtmlTextWriter writer)
409                         {
410                                 base.AddAttributesToRender (writer);
411                                 if (ID == null)
412                                         writer.AddAttribute ("id", parent.ClientID);
413                         }
414                 }
415
416                 private Table RenderTable {
417                         get {
418                                 if (render_table == null) {
419                                         render_table = new TableID (this);
420                                         render_table.AutoID = false;
421                                 }
422                                 return render_table;
423                         }
424                 }
425
426                 private void CreateRenderColumns (PagedDataSource paged, bool useDataSource)
427                 {
428                         if (useDataSource) {
429                                 ArrayList columns_list = CreateColumnSet (paged, useDataSource);
430                                 render_columns = new DataGridColumn [columns_list.Count];
431
432                                 for (int c = 0; c < render_columns.Length; c++) {
433                                         DataGridColumn col = (DataGridColumn) columns_list [c];
434                                         col.Set_Owner (this);
435                                         col.Initialize ();
436                                         render_columns [c] = col;
437                                 }
438                         } else {
439                                 render_columns = new DataGridColumn [Columns.Count];
440                                 Columns.CopyTo (render_columns, 0);
441                         }
442                 }
443
444                 [MonoTODO]
445                 [Browsable(false)]
446                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
447                 [WebSysDescription ("")]
448                 [WebCategory ("Paging")]
449                 public virtual DataGridItem SelectedItem {
450                         get {
451                                 if (SelectedIndex == -1)
452                                         return null;
453                                 return Items [SelectedIndex];
454                         }
455                 }
456
457 #if ONLY_1_1
458                 [Bindable(true)]
459 #endif
460                 [DefaultValue(false)]
461                 [WebSysDescription ("")]
462                 [WebCategory ("Appearance")]
463                 public virtual bool ShowFooter {
464                         get { return ViewState.GetBool ("ShowFooter", false); }
465                         set { ViewState ["ShowFooter"] = value; }
466                 }
467
468 #if ONLY_1_1
469                 [Bindable(true)]
470 #endif
471                 [DefaultValue(true)]
472                 [WebSysDescription ("")]
473                 [WebCategory ("Appearance")]
474                 public virtual bool ShowHeader {
475                         get { return ViewState.GetBool ("ShowHeader", true); }
476                         set { ViewState ["ShowHeader"] = value; }
477                 }
478
479                 [Browsable(false)]
480                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
481                 [WebSysDescription ("")]
482                 [WebCategory ("Appearance")]
483                 public virtual int VirtualItemCount {
484                         get { return ViewState.GetInt ("VirtualItemCount", 0); }
485                         set {
486                                 if (value < 0)
487                                         throw new ArgumentOutOfRangeException ("value");
488                                 ViewState ["VirtualItemCount"] = value;
489                         }
490                 }
491
492 #if NET_2_0
493                 protected override HtmlTextWriterTag TagKey {
494                         get { return HtmlTextWriterTag.Table; }
495                 }
496 #endif
497
498                 private TableStyle TableStyle {
499                         get { return (TableStyle) ControlStyle; }
500                 }
501
502                 static Type [] item_args = new Type [] {typeof (int) };
503                 void AddColumnsFromSource (PagedDataSource data_source)
504                 {
505                         PropertyDescriptorCollection props = null;
506                         Type ptype = null;
507                         bool no_items = false;
508
509                         // Use plain reflection for the Item property.
510                         // If we use TypeDescriptor, props will hold
511                         // all of the Type properties, which will be listed as columns
512                         Type ds_type = data_source.GetType ();
513                         PropertyInfo pinfo = ds_type.GetProperty ("Item", item_args);
514                         if (pinfo == null) {
515                                 IEnumerator items = (data_source.DataSource != null) ? data_source.GetEnumerator () : null;
516                                 if (items != null && items.MoveNext ()) {
517                                         object data = items.Current;
518                                         if ((data is ICustomTypeDescriptor) || (!IsBindableType(data.GetType())))
519                                                 props = TypeDescriptor.GetProperties (data);
520                                         else if (data != null)
521                                                 ptype = data.GetType ();
522                                         data_enumerator = items;
523                                 } else {
524                                         no_items = true;
525                                 }
526                         } else {
527                                 ptype = pinfo.PropertyType;
528                         }
529
530                         if (ptype != null) {
531                                 // Found the "Item" property
532                                 AddPropertyToColumns ();
533                         } else if (props != null) {
534                                 foreach (PropertyDescriptor pd in props)
535                                         AddPropertyToColumns (pd, false);
536                         } else if (!no_items) {
537                                 // This is not thrown for an empty ArrayList.
538                                 string msg = String.Format ("DataGrid '{0}' cannot autogenerate " +
539                                                         "columns from the given datasource. {1}", ID, ptype);
540                                 throw new HttpException (msg);
541                         }
542                 }
543
544                 protected virtual ArrayList CreateColumnSet (PagedDataSource dataSource, bool useDataSource)
545                 {
546                         ArrayList res = new ArrayList ();
547                         if (columns_list != null)
548                                 res.AddRange (columns_list);
549
550                         if (AutoGenerateColumns) {
551                                 if (useDataSource) {
552                                         data_enumerator = null;
553                                         PropertyDescriptorCollection props = dataSource.GetItemProperties (null);
554                                         DataSourceColumns.Clear ();
555                                         if (props != null) {
556                                                 foreach (PropertyDescriptor d in props)
557                                                         AddPropertyToColumns (d, false);
558                                         } else {
559                                                 AddColumnsFromSource (dataSource);
560                                         }
561                                 }
562
563                                 if (data_source_columns != null && data_source_columns.Count > 0)
564                                         res.AddRange (data_source_columns);
565                         }
566
567                         return res;
568                 }
569
570                 private void AddPropertyToColumns ()
571                 {
572                         BoundColumn b = new BoundColumn ();
573                         if (IsTrackingViewState) {
574                                 IStateManager m = (IStateManager) b;
575                                 m.TrackViewState ();
576                         }
577                         b.Set_Owner (this);
578                         b.HeaderText = "Item";
579                         b.SortExpression = "Item";
580                         b.DataField  = BoundColumn.thisExpr;
581                         DataSourceColumns.Add (b);
582                 }
583
584                 private void AddPropertyToColumns (PropertyDescriptor prop, bool tothis)
585                 {
586                         BoundColumn b = new BoundColumn ();
587                         b.Set_Owner (this);
588                         if (IsTrackingViewState) {
589                                 IStateManager m = (IStateManager) b;
590                                 m.TrackViewState ();
591                         }
592                         b.HeaderText = prop.Name;
593                         b.DataField = (tothis ? BoundColumn.thisExpr : prop.Name);
594                         b.SortExpression = prop.Name;
595                         DataSourceColumns.Add (b);
596                 }
597
598                 protected override void TrackViewState ()
599                 {
600                         base.TrackViewState ();
601
602                         if (pager_style != null)
603                                 pager_style.TrackViewState ();
604                         if (header_style != null)
605                                 header_style.TrackViewState ();
606                         if (footer_style != null)
607                                 footer_style.TrackViewState ();
608                         if (item_style != null)
609                                 item_style.TrackViewState ();
610                         if (alt_item_style != null)
611                                 alt_item_style.TrackViewState ();
612                         if (selected_style != null)
613                                 selected_style.TrackViewState ();
614                         if (edit_item_style != null)
615                                 edit_item_style.TrackViewState ();
616
617                         IStateManager manager = (IStateManager) columns;
618                         if (manager != null)
619                                 manager.TrackViewState ();
620                 }
621
622                 protected override object SaveViewState ()
623                 {
624                         object [] res = new object [10];
625
626                         res [0] = base.SaveViewState ();
627                         if (columns != null) {
628                                 IStateManager cm = (IStateManager) columns;
629                                 res [1] = cm.SaveViewState ();
630                         }
631                         if (pager_style != null)
632                                 res [2] = pager_style.SaveViewState ();
633                         if (header_style != null)
634                                 res [3] = header_style.SaveViewState ();
635                         if (footer_style != null)
636                                 res [4] = footer_style.SaveViewState ();
637                         if (item_style != null)
638                                 res [5] = item_style.SaveViewState ();
639                         if (alt_item_style != null)
640                                 res [6] = alt_item_style.SaveViewState ();
641                         if (selected_style != null)
642                                 res [7] = selected_style.SaveViewState ();
643                         if (edit_item_style != null)
644                                 res [8] = edit_item_style.SaveViewState ();
645
646                         if (data_source_columns != null) {
647                                 IStateManager m = (IStateManager) data_source_columns;
648                                 res [9] = m.SaveViewState ();
649                         }
650                         
651                         return res;
652                 }
653
654                 protected override void LoadViewState (object savedState)
655                 {
656                         object [] pieces = savedState as object [];
657
658                         if (pieces == null)
659                                 return;
660
661                         base.LoadViewState (pieces [0]);
662                         if (columns != null) {
663                                 IStateManager cm = (IStateManager) columns;
664                                 cm.LoadViewState (pieces [1]);
665                         }
666                         if (pieces [2] != null)
667                                 PagerStyle.LoadViewState (pieces [2]);
668                         if (pieces [3] != null)
669                                 HeaderStyle.LoadViewState (pieces [3]);
670                         if (pieces [4] != null)
671                                 FooterStyle.LoadViewState (pieces [4]);
672                         if (pieces [5] != null)
673                                 ItemStyle.LoadViewState (pieces [5]);
674                         if (pieces [6] != null)
675                                 AlternatingItemStyle.LoadViewState (pieces [6]);
676                         if (pieces [7] != null)
677                                 SelectedItemStyle.LoadViewState (pieces [7]);
678                         if (pieces [8] != null)
679                                 EditItemStyle.LoadViewState (pieces [8]);
680
681                         if (pieces [9] != null) {
682                                 // IStateManager manager = (IStateManager) DataSourceColumns;
683                                 // manager.LoadViewState (pieces [9]);
684                                 object [] cols = (object []) pieces [9];
685                                 foreach (object o in cols) {
686                                         BoundColumn c = new BoundColumn ();
687                                         c.Set_Owner (this);
688                                         ((IStateManager) c).LoadViewState (o);
689                                         DataSourceColumns.Add (c);
690                                 }
691                         }
692                 }
693
694                 protected override Style CreateControlStyle ()
695                 {
696                         TableStyle res = new TableStyle (ViewState);
697                         res.GridLines = GridLines.Both;
698                         res.CellSpacing = 0;
699                         return res;
700                 }
701
702                 protected virtual void InitializeItem (DataGridItem item, DataGridColumn [] columns)
703                 {
704                         bool th = UseAccessibleHeader && item.ItemType == ListItemType.Header;
705                         for (int i = 0; i < columns.Length; i++) {
706                                 TableCell cell = (th) ? new TableHeaderCell () : new TableCell ();
707                                 columns [i].InitializeCell (cell, i, item.ItemType);
708                                 item.Cells.Add (cell);
709                         }
710                 }
711
712                 protected virtual void InitializePager (DataGridItem item, int columnSpan, PagedDataSource pagedDataSource)
713                 {
714                         TableCell pager_cell;
715                         if (PagerStyle.Mode == PagerMode.NextPrev)
716                                 pager_cell = InitializeNextPrevPager (item, columnSpan, pagedDataSource);
717                         else
718                                 pager_cell = InitializeNumericPager (item, columnSpan, pagedDataSource);
719
720                         item.Controls.Add (pager_cell);
721                 }
722
723                 private TableCell InitializeNumericPager (DataGridItem item, int columnSpan,
724                                 PagedDataSource paged)
725                 {
726                         TableCell res = new TableCell ();
727                         res.ColumnSpan = columnSpan;
728
729                         int button_count = PagerStyle.PageButtonCount;
730                         int current = paged.CurrentPageIndex;
731                         int start = current - (current % button_count);
732                         int end = start + button_count;
733
734                         if (end > paged.PageCount)
735                                 end = paged.PageCount;
736
737                         if (start > 0) {
738                                 LinkButton link = new LinkButton ();
739                                 link.Text = "...";
740                                 link.CommandName = PageCommandName;
741                                 link.CommandArgument = start.ToString (CultureInfo.InvariantCulture);
742                                 link.CausesValidation = false;
743                                 res.Controls.Add (link);
744                                 res.Controls.Add (new LiteralControl ("&nbsp;"));
745                         }
746
747                         for (int i = start; i < end; i++) {
748                                 Control number = null;
749                                 string page = (i + 1).ToString (CultureInfo.InvariantCulture);
750                                 if (i != paged.CurrentPageIndex) {
751                                         LinkButton link = new LinkButton ();
752                                         link.Text = page;
753                                         link.CommandName = PageCommandName;
754                                         link.CommandArgument = page;
755                                         link.CausesValidation = false;
756                                         number = link;
757                                 } else {
758                                         Label pageLabel = new Label();
759                                         pageLabel.Text = page;
760                                         number = pageLabel;
761                                 }
762
763                                 res.Controls.Add (number);
764                                 if (i < end - 1)
765                                         res.Controls.Add (new LiteralControl ("&nbsp;"));
766                         }
767
768                         if (end < paged.PageCount) {
769                                 res.Controls.Add (new LiteralControl ("&nbsp;"));
770                                 LinkButton link = new LinkButton ();
771                                 link.Text = "...";
772                                 link.CommandName = PageCommandName;
773                                 link.CommandArgument = (end + 1).ToString (CultureInfo.InvariantCulture);
774                                 link.CausesValidation = false;
775                                 res.Controls.Add (link);
776                         }
777
778                         return res;
779                 }
780
781                 private TableCell InitializeNextPrevPager (DataGridItem item, int columnSpan, PagedDataSource paged)
782                 {
783                         TableCell res = new TableCell ();
784                         res.ColumnSpan = columnSpan;
785
786                         Control prev;
787                         Control next;
788
789                         if (paged.IsFirstPage) {
790                                 Label l = new Label ();
791                                 l.Text = PagerStyle.PrevPageText;
792                                 prev = l;
793                         } else {
794                                 LinkButton l = new LinkButton ();
795                                 l.Text = PagerStyle.PrevPageText;
796                                 l.CommandName = PageCommandName;
797                                 l.CommandArgument = PrevPageCommandArgument;
798                                 l.CausesValidation = false;
799                                 prev = l;
800                         }
801
802                         if (paged.Count > 0 && !paged.IsLastPage) {
803                                 LinkButton l = new LinkButton ();
804                                 l.Text = PagerStyle.NextPageText;
805                                 l.CommandName = PageCommandName;
806                                 l.CommandArgument = NextPageCommandArgument;
807                                 l.CausesValidation = false;
808                                 next = l;
809                         } else {
810                                 Label l = new Label ();
811                                 l.Text = PagerStyle.NextPageText;
812                                 next = l;
813                         }
814
815                         res.Controls.Add (prev);
816                         res.Controls.Add (new LiteralControl ("&nbsp;"));
817                         res.Controls.Add (next);
818
819                         return res;
820                 }
821                                 
822                 protected virtual DataGridItem CreateItem (int itemIndex, int dataSourceIndex,
823                                 ListItemType itemType)
824                 {
825                         DataGridItem res = new DataGridItem (itemIndex, dataSourceIndex, itemType);
826                         return res;
827                 }
828
829                 private DataGridItem CreateItem (int item_index, int data_source_index,
830                                 ListItemType type, bool data_bind, object data_item,
831                                 PagedDataSource paged)
832                 {
833                         DataGridItem res = CreateItem (item_index, data_source_index, type);
834                         DataGridItemEventArgs args = new DataGridItemEventArgs (res);
835                         bool no_pager = (type != ListItemType.Pager);
836
837                         if (no_pager) {
838                                 InitializeItem (res, render_columns);
839                                 if (data_bind)
840                                         res.DataItem = data_item;
841                                 OnItemCreated (args);
842                         } else {
843                                 InitializePager (res, render_columns.Length, paged);
844                                 if (pager_style != null)
845                                         res.ApplyStyle (pager_style);
846                                 OnItemCreated (args);
847                         }
848
849                         // Add before the column is bound, so that the
850                         // value is saved in the viewstate
851                         RenderTable.Controls.Add (res);
852
853                         if (no_pager && data_bind) {
854                                 res.DataBind ();
855                                 OnItemDataBound (args);
856                                 res.DataItem = null;
857                         }
858                         return res;
859                 }
860
861                 class NCollection : ICollection {
862                         int n;
863 #if TARGET_JVM
864                         class SequenceEnumerator : IEnumerator {
865                                 readonly int _max;
866                                 object _current;
867                                 public SequenceEnumerator(int max) {
868                                         _max = max;
869                                         Reset();
870                                 }
871
872                                 public bool MoveNext() {
873                                         _current = (int)_current + 1;
874                                         return (int)_current >= 0 && (int)_current < _max;
875                                 }
876
877                                 public void Reset() {
878                                         _current = -1;
879                                 }
880
881                                 public object Current {
882                                         get { return _current; }
883                                 }
884                         }
885 #endif
886
887                         public NCollection (int n)
888                         {
889                                 this.n = n;
890                         }
891
892                         public IEnumerator GetEnumerator ()
893                         {
894 #if TARGET_JVM
895                                 return new SequenceEnumerator(n);
896 #else
897                                 for (int i = 0; i < n; i++)
898                                         yield return i;
899 #endif
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
925                         IEnumerable data_source;
926                         ArrayList keys = null;
927                         if (useDataSource) {
928                                 data_source = DataSourceResolver.ResolveDataSource (DataSource, DataMember);
929                                 keys = DataKeysArray;
930                                 keys.Clear ();
931                         } else {
932                                 int nitems = ViewState.GetInt ("Items", 0);
933                                 data_source = new NCollection (nitems);
934                         }
935
936                         paged_data_source = new PagedDataSource ();
937                         PagedDataSource pds = paged_data_source;
938                         pds.AllowPaging = AllowPaging;
939                         pds.AllowCustomPaging = AllowCustomPaging;
940                         pds.DataSource = data_source;
941                         pds.CurrentPageIndex = CurrentPageIndex;
942                         pds.PageSize = PageSize;
943                         pds.VirtualCount = VirtualItemCount;
944
945                         if ((pds.IsPagingEnabled) && (pds.PageCount < pds.CurrentPageIndex))
946                                 throw new HttpException ("Invalid DataGrid PageIndex");
947                                 
948                         CreateRenderColumns (paged_data_source, useDataSource);
949                         if (useDataSource) {
950                                 if (DataSource != null)
951                                         Controls.Add (RenderTable);
952                         } else {
953                                 Controls.Add (RenderTable);
954                         }
955
956                         if (pds.IsPagingEnabled)
957                                 CreateItem (-1, -1, ListItemType.Pager, false, null, pds);
958
959                         CreateItem (-1, -1, ListItemType.Header, useDataSource, null, pds);
960
961                         // No indexer on PagedDataSource so we have to do
962                         // this silly foreach and index++
963                         if (items_list == null)
964                                 items_list = new ArrayList ();
965                         else
966                                 items_list.Clear();
967
968                         bool skip_first = false;
969                         IEnumerator enumerator = null;
970                         if (data_enumerator != null) {
971                                 // replaced when creating bound columns
972                                 enumerator = data_enumerator;
973                                 skip_first = true;
974                         } else if (pds.DataSource != null) {
975                                 enumerator = pds.GetEnumerator ();
976                         } else {
977                                 enumerator = null;
978                         }
979
980                         int index = 0;
981                         bool first = true;
982                         string key = null;
983                         int dataset_index = pds.FirstIndexInPage;
984                         int selected_index = SelectedIndex;
985                         int edit_item_index = EditItemIndex;
986                         while (enumerator != null && (skip_first || enumerator.MoveNext ())) {
987                                 // MS does not render <table blah></table> on empty datasource.
988                                 if (first) {
989                                         first = false;
990                                         key = DataKeyField;
991                                         skip_first = false;
992                                 }
993                                 object data = enumerator.Current;
994                                 // This will throw if the DataKeyField is not there. As on MS, this
995                                 // will not be hit on an empty datasource.
996                                 // The values stored here can be used in events so that you can
997                                 // get, for example, the row that was clicked
998                                 // (data.Rows.Find (ItemsGrid.DataKeys [e.Item.ItemIndex]))
999                                 // BaseDataList will keep the array across postbacks.
1000                                 if (useDataSource && key != "")
1001                                         keys.Add (DataBinder.GetPropertyValue (data, key));
1002
1003                                 ListItemType type = ListItemType.Item;
1004                                 if (index == edit_item_index) 
1005                                         type = ListItemType.EditItem;
1006                                 else if (index == selected_index) 
1007                                         type = ListItemType.SelectedItem;
1008                                 else if (index % 2 != 0) 
1009                                         type = ListItemType.AlternatingItem;
1010
1011                                 items_list.Add (CreateItem (index, dataset_index, type, useDataSource, data, pds));
1012                                 index++;
1013                                 dataset_index++;
1014                         }
1015
1016                         CreateItem (-1, -1, ListItemType.Footer, useDataSource, null, paged_data_source);
1017                         if (pds.IsPagingEnabled) {
1018                                 CreateItem (-1, -1, ListItemType.Pager, false, null, paged_data_source);
1019                                 if (useDataSource)
1020                                         ViewState ["Items"] = pds.IsCustomPagingEnabled ? index : pds.DataSourceCount;
1021                         } else if (useDataSource) {
1022                                 ViewState ["Items"] = index;
1023                         }
1024                 }
1025
1026                 void ApplyColumnStyle (TableCellCollection cells, ListItemType type)
1027                 {
1028                         int ncells = Math.Min (cells.Count, render_columns.Length);
1029                         if (ncells <= 0)
1030                                 return;
1031
1032                         for (int i = 0; i < ncells; i++) {
1033                                 Style style = null;
1034                                 TableCell cell = cells [i];
1035                                 DataGridColumn column = render_columns [i];
1036                                 if (!column.Visible) {
1037                                         cell.Visible = false;
1038                                         continue;
1039                                 }
1040
1041                                 style = column.GetStyle (type);
1042                                 if (style != null)
1043                                         cell.MergeStyle (style);
1044                         }
1045                 }
1046
1047                 protected override void PrepareControlHierarchy ()
1048                 {
1049                         if (!HasControls () || Controls.Count == 0)
1050                                 return; // No one called CreateControlHierarchy() with DataSource != null
1051
1052                         Table rt = render_table;
1053                         rt.CopyBaseAttributes (this);
1054                         rt.ApplyStyle (ControlStyle);
1055
1056                         rt.Caption = Caption;
1057                         rt.CaptionAlign = CaptionAlign;
1058                         rt.Enabled = Enabled;
1059
1060                         bool top_pager = true;
1061                         Style alt = null;
1062                         foreach (DataGridItem item in rt.Rows) {
1063                                 
1064                                 switch (item.ItemType) {
1065                                 case ListItemType.Item:
1066                                         item.MergeStyle (item_style);
1067                                         ApplyColumnStyle (item.Cells, ListItemType.Item);
1068                                         break;
1069                                 case ListItemType.AlternatingItem:
1070                                         if (alt == null) {
1071                                                 if (alt_item_style != null) {
1072                                                         alt = new TableItemStyle ();
1073                                                         alt.CopyFrom (item_style);
1074                                                         alt.CopyFrom (alt_item_style);
1075                                                 } else {
1076                                                         alt = item_style;
1077                                                 }
1078                                         }
1079
1080                                         item.MergeStyle (alt);
1081                                         ApplyColumnStyle (item.Cells, ListItemType.AlternatingItem);
1082                                         break;
1083                                 case ListItemType.EditItem:
1084                                         item.MergeStyle (edit_item_style);
1085                                         ApplyColumnStyle (item.Cells, ListItemType.EditItem);
1086                                         break;
1087                                 case ListItemType.Footer:
1088                                         if (!ShowFooter) {
1089                                                 item.Visible = false;
1090                                                 break;
1091                                         }
1092                                         if (footer_style != null)
1093                                                 item.MergeStyle (footer_style);
1094                                         ApplyColumnStyle (item.Cells, ListItemType.Footer);
1095                                         break;
1096                                 case ListItemType.Header:
1097                                         if (!ShowHeader) {
1098                                                 item.Visible = false;
1099                                                 break;
1100                                         }
1101                                         if (header_style != null)
1102                                                 item.MergeStyle (header_style);
1103                                         ApplyColumnStyle (item.Cells, ListItemType.Header);
1104                                         break;
1105                                 case ListItemType.SelectedItem:
1106                                         if (selected_style != null)
1107                                                 item.MergeStyle (selected_style);
1108                                         else
1109                                                 item.MergeStyle (item_style);
1110                                         ApplyColumnStyle (item.Cells, ListItemType.SelectedItem);
1111                                         break;
1112                                 case ListItemType.Separator:
1113                                         ApplyColumnStyle (item.Cells, ListItemType.Separator);
1114                                         break;
1115                                 case ListItemType.Pager:
1116                                         DataGridPagerStyle ps = PagerStyle;
1117                                         if (ps.Visible == false || !paged_data_source.IsPagingEnabled) {
1118                                                 item.Visible = false;
1119                                         } else {
1120                                                 if (top_pager)
1121                                                         item.Visible = (ps.Position != PagerPosition.Bottom);
1122                                                 else
1123                                                         item.Visible = (ps.Position != PagerPosition.Top);
1124                                                 top_pager = false;
1125                                         }
1126
1127                                         if (item.Visible)
1128                                                 item.MergeStyle (pager_style);
1129                                         break;
1130                                 }
1131                         }
1132                 }
1133
1134                 protected override bool OnBubbleEvent (object source, EventArgs e)
1135                 {
1136                         DataGridCommandEventArgs de = e as DataGridCommandEventArgs;
1137
1138                         if (de == null)
1139                                 return false;
1140
1141                         string cn = de.CommandName;
1142                         CultureInfo inv = CultureInfo.InvariantCulture;
1143
1144                         OnItemCommand (de);
1145                         if (String.Compare (cn, CancelCommandName, true, inv) == 0) {
1146                                 OnCancelCommand (de);
1147                         } else if (String.Compare (cn, DeleteCommandName, true, inv) == 0) {
1148                                 OnDeleteCommand (de);
1149                         } else if (String.Compare (cn, EditCommandName, true, inv) == 0) {
1150                                 OnEditCommand (de);
1151                         } else if (String.Compare (cn, SelectCommandName, true, inv) == 0) {
1152                                 SelectedIndex = de.Item.ItemIndex;
1153                                 OnSelectedIndexChanged (de);
1154                         } else if (String.Compare (cn, SortCommandName, true, inv) == 0) {
1155                                 DataGridSortCommandEventArgs se = new DataGridSortCommandEventArgs (de.CommandSource, de);
1156                                 OnSortCommand (se);
1157                         } else if (String.Compare (cn, UpdateCommandName, true, inv) == 0) {
1158                                 OnUpdateCommand (de);
1159                         } else if (String.Compare (cn, PageCommandName, true, inv) == 0) {
1160                                 int new_index;
1161                                 if (String.Compare ((string) de.CommandArgument,
1162                                                     NextPageCommandArgument, true, inv) == 0) {
1163                                         new_index = CurrentPageIndex + 1;
1164                                 } else if (String.Compare ((string) de.CommandArgument,
1165                                                            PrevPageCommandArgument, true, inv) == 0) {
1166                                         new_index = CurrentPageIndex - 1;
1167                                 } else {
1168                                         // It seems to just assume it's an int and parses, no
1169                                         // checks to make sure its valid or anything.
1170                                         //  also it's always one less then specified, not sure
1171                                         // why that is.
1172                                         new_index = Int32.Parse ((string) de.CommandArgument, inv) - 1;
1173                                 }
1174                                 DataGridPageChangedEventArgs pc = new DataGridPageChangedEventArgs (
1175                                         de.CommandSource, new_index);
1176                                 OnPageIndexChanged (pc);
1177                         }
1178
1179                         return true;
1180                 }
1181
1182                 protected virtual void OnCancelCommand (DataGridCommandEventArgs e)
1183                 {
1184                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [CancelCommandEvent];
1185                         if (handler != null)
1186                                 handler (this, e);
1187                 }
1188
1189                 protected virtual void OnDeleteCommand (DataGridCommandEventArgs e)
1190                 {
1191                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [DeleteCommandEvent];
1192                         if (handler != null)
1193                                 handler (this, e);
1194                 }
1195
1196                 protected virtual void OnEditCommand (DataGridCommandEventArgs e)
1197                 {
1198                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [EditCommandEvent];
1199                         if (handler != null)
1200                                 handler (this, e);
1201                 }
1202
1203                 protected virtual void OnItemCommand (DataGridCommandEventArgs e)
1204                 {
1205                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [ItemCommandEvent];
1206                         if (handler != null)
1207                                 handler (this, e);
1208                 }
1209
1210                 protected virtual void OnItemCreated (DataGridItemEventArgs e)
1211                 {
1212                         DataGridItemEventHandler handler = (DataGridItemEventHandler) Events [ItemCreatedEvent];
1213                         if (handler != null)
1214                                 handler (this, e);
1215                 }
1216
1217                 protected virtual void OnItemDataBound (DataGridItemEventArgs e)
1218                 {
1219                         DataGridItemEventHandler handler = (DataGridItemEventHandler) Events [ItemDataBoundEvent];
1220                         if (handler != null)
1221                                 handler (this, e);
1222                 }
1223
1224                 protected virtual void OnPageIndexChanged (DataGridPageChangedEventArgs e)
1225                 {
1226                         DataGridPageChangedEventHandler handler = (DataGridPageChangedEventHandler) Events [PageIndexChangedEvent];
1227                         if (handler != null)
1228                                 handler (this, e);
1229                 }
1230
1231                 protected virtual void OnSortCommand (DataGridSortCommandEventArgs e)
1232                 {
1233                         DataGridSortCommandEventHandler handler = (DataGridSortCommandEventHandler) Events [SortCommandEvent];
1234                         if (handler != null)
1235                                 handler (this, e);
1236                 }
1237
1238                 protected virtual void OnUpdateCommand (DataGridCommandEventArgs e)
1239                 {
1240                         DataGridCommandEventHandler handler = (DataGridCommandEventHandler) Events [UpdateCommandEvent];
1241                         if (handler != null)
1242                                 handler (this, e);
1243                 }
1244
1245                 [WebSysDescription ("")]
1246                 [WebCategory ("Action")]
1247                 public event DataGridCommandEventHandler CancelCommand {
1248                         add { Events.AddHandler (CancelCommandEvent, value); }
1249                         remove { Events.RemoveHandler (CancelCommandEvent, value); }
1250                 }
1251
1252                 [WebSysDescription ("")]
1253                 [WebCategory ("Action")]
1254                 public event DataGridCommandEventHandler DeleteCommand {
1255                         add { Events.AddHandler (DeleteCommandEvent, value); }
1256                         remove { Events.RemoveHandler (DeleteCommandEvent, value); }
1257                 }
1258
1259                 [WebSysDescription ("")]
1260                 [WebCategory ("Action")]
1261                 public event DataGridCommandEventHandler EditCommand {
1262                         add { Events.AddHandler (EditCommandEvent, value); }
1263                         remove { Events.RemoveHandler (EditCommandEvent, value); }
1264                 }
1265
1266                 [WebSysDescription ("")]
1267                 [WebCategory ("Action")]
1268                 public event DataGridCommandEventHandler ItemCommand {
1269                         add { Events.AddHandler (ItemCommandEvent, value); }
1270                         remove { Events.RemoveHandler (ItemCommandEvent, value); }
1271                         
1272                 }
1273
1274                 [WebSysDescription ("")]
1275                 [WebCategory ("Action")]
1276                 public event DataGridItemEventHandler ItemCreated {
1277                         add { Events.AddHandler (ItemCreatedEvent, value); }
1278                         remove { Events.RemoveHandler (ItemCreatedEvent, value); }
1279                 }
1280
1281                 [WebSysDescription ("")]
1282                 [WebCategory ("Action")]
1283                 public event DataGridItemEventHandler ItemDataBound {
1284                         add { Events.AddHandler (ItemDataBoundEvent, value); }
1285                         remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
1286                 }
1287
1288                 [WebSysDescription ("")]
1289                 [WebCategory ("Action")]
1290                 public event DataGridPageChangedEventHandler PageIndexChanged {
1291                         add { Events.AddHandler (PageIndexChangedEvent, value); }
1292                         remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
1293                 }
1294
1295                 [WebSysDescription ("")]
1296                 [WebCategory ("Action")]
1297                 public event DataGridSortCommandEventHandler SortCommand {
1298                         add { Events.AddHandler (SortCommandEvent, value); }
1299                         remove { Events.RemoveHandler (SortCommandEvent, value); }
1300                 }
1301
1302                 [WebSysDescription ("")]
1303                 [WebCategory ("Action")]
1304                 public event DataGridCommandEventHandler UpdateCommand {
1305                         add { Events.AddHandler (UpdateCommandEvent, value); }
1306                         remove { Events.AddHandler (UpdateCommandEvent, value); }
1307                 }
1308         }
1309 }
1310