2 // System.Web.UI.WebControls.DetailsView.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
36 using System.Security.Permissions;
39 using System.Reflection;
41 namespace System.Web.UI.WebControls
43 [SupportsEventValidation]
44 [ToolboxDataAttribute ("<{0}:DetailsView runat=\"server\" Width=\"125px\" Height=\"50px\"></{0}:DetailsView>")]
\r
45 [DesignerAttribute ("System.Web.UI.Design.WebControls.DetailsViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
46 [ControlValuePropertyAttribute ("SelectedValue")]
47 [DefaultEventAttribute ("PageIndexChanging")]
48 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
49 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
50 public class DetailsView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IDataItemContainer, INamingContainer, IPostBackEventHandler, IPostBackContainer
55 DetailsViewRowCollection rows;
56 DetailsViewRow headerRow;
57 DetailsViewRow footerRow;
58 DetailsViewRow bottomPagerRow;
59 DetailsViewRow topPagerRow;
61 IOrderedDictionary currentEditRowKeys;
62 IOrderedDictionary currentEditNewValues;
63 IOrderedDictionary currentEditOldValues;
65 ITemplate pagerTemplate;
66 ITemplate emptyDataTemplate;
67 ITemplate headerTemplate;
68 ITemplate footerTemplate;
70 PropertyDescriptor[] cachedKeyProperties;
71 readonly string[] emptyKeys = new string[0];
73 CommandField commandField;
74 DetailsViewRow commandRow;
77 DataControlFieldCollection columns;
78 PagerSettings pagerSettings;
80 TableItemStyle alternatingRowStyle;
81 TableItemStyle editRowStyle;
82 TableItemStyle insertRowStyle;
83 TableItemStyle emptyDataRowStyle;
84 TableItemStyle footerStyle;
85 TableItemStyle headerStyle;
86 TableItemStyle pagerStyle;
87 TableItemStyle rowStyle;
88 TableItemStyle commandRowStyle;
89 TableItemStyle fieldHeaderStyle;
92 DataKey oldEditValues;
93 AutoGeneratedFieldProperties[] autoFieldProperties;
95 private static readonly object PageIndexChangedEvent = new object();
96 private static readonly object PageIndexChangingEvent = new object();
97 private static readonly object ItemCommandEvent = new object();
98 private static readonly object ItemCreatedEvent = new object();
99 private static readonly object ItemDeletedEvent = new object();
100 private static readonly object ItemDeletingEvent = new object();
101 private static readonly object ItemInsertedEvent = new object();
102 private static readonly object ItemInsertingEvent = new object();
103 private static readonly object ModeChangingEvent = new object();
104 private static readonly object ModeChangedEvent = new object();
105 private static readonly object ItemUpdatedEvent = new object();
106 private static readonly object ItemUpdatingEvent = new object();
110 DetailsViewMode currentMode = DetailsViewMode.ReadOnly;
113 public DetailsView ()
115 rows = new DetailsViewRowCollection (new ArrayList ());
118 public event EventHandler PageIndexChanged {
119 add { Events.AddHandler (PageIndexChangedEvent, value); }
120 remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
123 public event DetailsViewPageEventHandler PageIndexChanging {
124 add { Events.AddHandler (PageIndexChangingEvent, value); }
125 remove { Events.RemoveHandler (PageIndexChangingEvent, value); }
128 public event DetailsViewCommandEventHandler ItemCommand {
129 add { Events.AddHandler (ItemCommandEvent, value); }
130 remove { Events.RemoveHandler (ItemCommandEvent, value); }
133 public event EventHandler ItemCreated {
134 add { Events.AddHandler (ItemCreatedEvent, value); }
135 remove { Events.RemoveHandler (ItemCreatedEvent, value); }
138 public event DetailsViewDeletedEventHandler ItemDeleted {
139 add { Events.AddHandler (ItemDeletedEvent, value); }
140 remove { Events.RemoveHandler (ItemDeletedEvent, value); }
143 public event DetailsViewDeleteEventHandler ItemDeleting {
144 add { Events.AddHandler (ItemDeletingEvent, value); }
145 remove { Events.RemoveHandler (ItemDeletingEvent, value); }
148 public event DetailsViewInsertedEventHandler ItemInserted {
149 add { Events.AddHandler (ItemInsertedEvent, value); }
150 remove { Events.RemoveHandler (ItemInsertedEvent, value); }
153 public event DetailsViewInsertEventHandler ItemInserting {
154 add { Events.AddHandler (ItemInsertingEvent, value); }
155 remove { Events.RemoveHandler (ItemInsertingEvent, value); }
158 public event DetailsViewModeEventHandler ModeChanging {
159 add { Events.AddHandler (ModeChangingEvent, value); }
160 remove { Events.RemoveHandler (ModeChangingEvent, value); }
163 public event EventHandler ModeChanged {
164 add { Events.AddHandler (ModeChangedEvent, value); }
165 remove { Events.RemoveHandler (ModeChangedEvent, value); }
168 public event DetailsViewUpdatedEventHandler ItemUpdated {
169 add { Events.AddHandler (ItemUpdatedEvent, value); }
170 remove { Events.RemoveHandler (ItemUpdatedEvent, value); }
173 public event DetailsViewUpdateEventHandler ItemUpdating {
174 add { Events.AddHandler (ItemUpdatingEvent, value); }
175 remove { Events.RemoveHandler (ItemUpdatingEvent, value); }
178 protected virtual void OnPageIndexChanged (EventArgs e)
180 if (Events != null) {
181 EventHandler eh = (EventHandler) Events [PageIndexChangedEvent];
182 if (eh != null) eh (this, e);
186 protected virtual void OnPageIndexChanging (DetailsViewPageEventArgs e)
188 if (Events != null) {
189 DetailsViewPageEventHandler eh = (DetailsViewPageEventHandler) Events [PageIndexChangingEvent];
190 if (eh != null) eh (this, e);
194 protected virtual void OnItemCommand (DetailsViewCommandEventArgs e)
196 if (Events != null) {
197 DetailsViewCommandEventHandler eh = (DetailsViewCommandEventHandler) Events [ItemCommandEvent];
198 if (eh != null) eh (this, e);
202 protected virtual void OnItemCreated (EventArgs e)
204 if (Events != null) {
205 EventHandler eh = (EventHandler) Events [ItemCreatedEvent];
206 if (eh != null) eh (this, e);
210 protected virtual void OnItemDeleted (DetailsViewDeletedEventArgs e)
212 if (Events != null) {
213 DetailsViewDeletedEventHandler eh = (DetailsViewDeletedEventHandler) Events [ItemDeletedEvent];
214 if (eh != null) eh (this, e);
218 protected virtual void OnItemInserted (DetailsViewInsertedEventArgs e)
220 if (Events != null) {
221 DetailsViewInsertedEventHandler eh = (DetailsViewInsertedEventHandler) Events [ItemInsertedEvent];
222 if (eh != null) eh (this, e);
226 protected virtual void OnItemInserting (DetailsViewInsertEventArgs e)
228 if (Events != null) {
229 DetailsViewInsertEventHandler eh = (DetailsViewInsertEventHandler) Events [ItemInsertingEvent];
230 if (eh != null) eh (this, e);
234 protected virtual void OnItemDeleting (DetailsViewDeleteEventArgs e)
236 if (Events != null) {
237 DetailsViewDeleteEventHandler eh = (DetailsViewDeleteEventHandler) Events [ItemDeletingEvent];
238 if (eh != null) eh (this, e);
242 protected virtual void OnModeChanged (EventArgs e)
244 if (Events != null) {
245 EventHandler eh = (EventHandler) Events [ModeChangedEvent];
246 if (eh != null) eh (this, e);
250 protected virtual void OnModeChanging (DetailsViewModeEventArgs e)
252 if (Events != null) {
253 DetailsViewModeEventHandler eh = (DetailsViewModeEventHandler) Events [ModeChangingEvent];
254 if (eh != null) eh (this, e);
258 protected virtual void OnItemUpdated (DetailsViewUpdatedEventArgs e)
260 if (Events != null) {
261 DetailsViewUpdatedEventHandler eh = (DetailsViewUpdatedEventHandler) Events [ItemUpdatedEvent];
262 if (eh != null) eh (this, e);
266 protected virtual void OnItemUpdating (DetailsViewUpdateEventArgs e)
268 if (Events != null) {
269 DetailsViewUpdateEventHandler eh = (DetailsViewUpdateEventHandler) Events [ItemUpdatingEvent];
270 if (eh != null) eh (this, e);
275 [WebCategoryAttribute ("Paging")]
276 [DefaultValueAttribute (false)]
277 public virtual bool AllowPaging {
279 object ob = ViewState ["AllowPaging"];
280 if (ob != null) return (bool) ob;
284 ViewState ["AllowPaging"] = value;
289 [DefaultValueAttribute (null)]
290 [WebCategoryAttribute ("Styles")]
291 [PersistenceMode (PersistenceMode.InnerProperty)]
292 [NotifyParentProperty (true)]
293 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
294 public TableItemStyle AlternatingRowStyle {
296 if (alternatingRowStyle == null) {
297 alternatingRowStyle = new TableItemStyle ();
298 if (IsTrackingViewState)
299 alternatingRowStyle.TrackViewState();
301 return alternatingRowStyle;
305 [WebCategoryAttribute ("Behavior")]
306 [DefaultValueAttribute (false)]
307 public virtual bool AutoGenerateEditButton {
309 object ob = ViewState ["AutoGenerateEditButton"];
310 if (ob != null) return (bool) ob;
314 ViewState ["AutoGenerateEditButton"] = value;
319 [WebCategoryAttribute ("Behavior")]
320 [DefaultValueAttribute (false)]
321 public virtual bool AutoGenerateDeleteButton {
323 object ob = ViewState ["AutoGenerateDeleteButton"];
324 if (ob != null) return (bool) ob;
328 ViewState ["AutoGenerateDeleteButton"] = value;
333 [WebCategoryAttribute ("Behavior")]
334 [DefaultValueAttribute (false)]
335 public virtual bool AutoGenerateInsertButton {
337 object ob = ViewState ["AutoGenerateInsertButton"];
338 if (ob != null) return (bool) ob;
342 ViewState ["AutoGenerateInsertButton"] = value;
347 [WebCategoryAttribute ("Behavior")]
348 [DefaultValueAttribute (true)]
349 public virtual bool AutoGenerateRows {
351 object ob = ViewState ["AutoGenerateRows"];
352 if (ob != null) return (bool) ob;
356 ViewState ["AutoGenerateRows"] = value;
361 [UrlPropertyAttribute]
362 [WebCategoryAttribute ("Appearance")]
363 [DefaultValueAttribute ("")]
364 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
365 public virtual string BackImageUrl {
367 object ob = ViewState ["BackImageUrl"];
368 if (ob != null) return (string) ob;
372 ViewState ["BackImageUrl"] = value;
377 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
378 [BrowsableAttribute (false)]
379 public virtual DetailsViewRow BottomPagerRow {
382 return bottomPagerRow;
386 [WebCategoryAttribute ("Accessibility")]
387 [DefaultValueAttribute ("")]
388 [LocalizableAttribute (true)]
389 public virtual string Caption {
391 object ob = ViewState ["Caption"];
392 if (ob != null) return (string) ob;
396 ViewState ["Caption"] = value;
401 [WebCategoryAttribute ("Accessibility")]
402 [DefaultValueAttribute (TableCaptionAlign.NotSet)]
403 public virtual TableCaptionAlign CaptionAlign
406 object o = ViewState ["CaptionAlign"];
407 if(o != null) return (TableCaptionAlign) o;
408 return TableCaptionAlign.NotSet;
411 ViewState ["CaptionAlign"] = value;
416 [WebCategoryAttribute ("Layout")]
417 [DefaultValueAttribute (-1)]
418 public virtual int CellPadding
421 object o = ViewState ["CellPadding"];
422 if (o != null) return (int) o;
427 throw new ArgumentOutOfRangeException ("< -1");
\r
428 ViewState["CellPadding"] = value;
\r
433 [WebCategoryAttribute ("Layout")]
434 [DefaultValueAttribute (0)]
435 public virtual int CellSpacing
438 object o = ViewState ["CellSpacing"];
439 if (o != null) return (int) o;
444 throw new ArgumentOutOfRangeException ("< -1");
\r
445 ViewState ["CellSpacing"] = value;
450 [DefaultValueAttribute (null)]
451 [WebCategoryAttribute ("Styles")]
452 [PersistenceMode (PersistenceMode.InnerProperty)]
453 [NotifyParentProperty (true)]
454 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
455 public TableItemStyle CommandRowStyle {
457 if (commandRowStyle == null) {
458 commandRowStyle = new TableItemStyle ();
459 if (IsTrackingViewState)
460 commandRowStyle.TrackViewState();
462 return commandRowStyle;
466 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
467 [BrowsableAttribute (false)]
\r
468 public DetailsViewMode CurrentMode {
474 [DefaultValueAttribute (DetailsViewMode.ReadOnly)]
\r
475 [WebCategoryAttribute ("Behavior")]
\r
476 public virtual DetailsViewMode DefaultMode {
478 object o = ViewState ["DefaultMode"];
479 if (o != null) return (DetailsViewMode) o;
480 return DetailsViewMode.ReadOnly;
483 ViewState ["DefaultMode"] = value;
488 [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
489 [MergablePropertyAttribute (false)]
490 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
491 [DefaultValueAttribute (null)]
492 [WebCategoryAttribute ("Misc")]
493 public virtual DataControlFieldCollection Fields {
495 if (columns == null) {
496 columns = new DataControlFieldCollection ();
497 columns.FieldsChanged += new EventHandler (OnFieldsChanged);
498 if (IsTrackingViewState)
499 ((IStateManager)columns).TrackViewState ();
505 [DefaultValueAttribute (null)]
506 [WebCategoryAttribute ("Data")]
507 [TypeConverter (typeof(StringArrayConverter))]
508 [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
509 public virtual string[] DataKeyNames
512 object o = ViewState ["DataKeyNames"];
513 if (o != null) return (string[]) o;
517 ViewState ["DataKeyNames"] = value;
522 [BrowsableAttribute (false)]
523 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
524 public virtual DataKey DataKey {
531 [WebCategoryAttribute ("Styles")]
532 [PersistenceMode (PersistenceMode.InnerProperty)]
533 [NotifyParentProperty (true)]
534 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
535 [DefaultValueAttribute (null)]
\r
536 public TableItemStyle EditRowStyle {
538 if (editRowStyle == null) {
539 editRowStyle = new TableItemStyle ();
540 if (IsTrackingViewState)
541 editRowStyle.TrackViewState();
547 [WebCategoryAttribute ("Styles")]
548 [PersistenceMode (PersistenceMode.InnerProperty)]
549 [NotifyParentProperty (true)]
550 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
551 [DefaultValueAttribute (null)]
\r
552 public TableItemStyle EmptyDataRowStyle {
554 if (emptyDataRowStyle == null) {
555 emptyDataRowStyle = new TableItemStyle ();
556 if (IsTrackingViewState)
557 emptyDataRowStyle.TrackViewState();
559 return emptyDataRowStyle;
563 [DefaultValue (null)]
564 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
565 [PersistenceMode (PersistenceMode.InnerProperty)]
567 public virtual ITemplate EmptyDataTemplate {
568 get { return emptyDataTemplate; }
569 set { emptyDataTemplate = value; RequireBinding (); }
572 [LocalizableAttribute (true)]
573 [WebCategoryAttribute ("Appearance")]
574 [DefaultValueAttribute ("")]
575 public virtual string EmptyDataText {
577 object ob = ViewState ["EmptyDataText"];
578 if (ob != null) return (string) ob;
582 ViewState ["EmptyDataText"] = value;
587 [WebCategoryAttribute ("Behavior")]
588 [DefaultValueAttribute (false)]
589 public virtual bool EnablePagingCallbacks {
591 object ob = ViewState ["EnablePagingCallbacks"];
592 if (ob != null) return (bool) ob;
596 ViewState ["EnablePagingCallbacks"] = value;
601 [WebCategoryAttribute ("Styles")]
602 [PersistenceMode (PersistenceMode.InnerProperty)]
603 [NotifyParentProperty (true)]
604 [DefaultValue (null)]
605 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
606 public TableItemStyle FieldHeaderStyle {
608 if (fieldHeaderStyle == null) {
609 fieldHeaderStyle = new TableItemStyle ();
610 if (IsTrackingViewState)
611 fieldHeaderStyle.TrackViewState();
613 return fieldHeaderStyle;
617 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
618 [BrowsableAttribute (false)]
619 public virtual DetailsViewRow FooterRow {
621 EnsureChildControls ();
626 [DefaultValue (null)]
627 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
628 [PersistenceMode (PersistenceMode.InnerProperty)]
630 public virtual ITemplate FooterTemplate {
631 get { return footerTemplate; }
632 set { footerTemplate = value; RequireBinding (); }
635 [LocalizableAttribute (true)]
\r
636 [WebCategoryAttribute ("Appearance")]
\r
637 [DefaultValueAttribute ("")]
\r
638 public virtual string FooterText {
640 object ob = ViewState ["FooterText"];
641 if (ob != null) return (string) ob;
645 ViewState ["FooterText"] = value;
650 [WebCategoryAttribute ("Styles")]
651 [PersistenceMode (PersistenceMode.InnerProperty)]
652 [NotifyParentProperty (true)]
653 [DefaultValue (null)]
654 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
655 public TableItemStyle FooterStyle {
657 if (footerStyle == null) {
658 footerStyle = new TableItemStyle ();
659 if (IsTrackingViewState)
660 footerStyle.TrackViewState();
666 [WebCategoryAttribute ("Appearance")]
667 [DefaultValueAttribute (GridLines.Both)]
668 public virtual GridLines GridLines {
670 object ob = ViewState ["GridLines"];
671 if (ob != null) return (GridLines) ob;
672 return GridLines.Both;
675 ViewState ["GridLines"] = value;
679 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
680 [BrowsableAttribute (false)]
681 public virtual DetailsViewRow HeaderRow {
683 EnsureChildControls ();
688 [WebCategoryAttribute ("Styles")]
689 [PersistenceMode (PersistenceMode.InnerProperty)]
690 [NotifyParentProperty (true)]
691 [DefaultValue (null)]
692 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
693 public TableItemStyle HeaderStyle {
695 if (headerStyle == null) {
696 headerStyle = new TableItemStyle ();
697 if (IsTrackingViewState)
698 headerStyle.TrackViewState();
704 [DefaultValue (null)]
705 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
706 [PersistenceMode (PersistenceMode.InnerProperty)]
708 public virtual ITemplate HeaderTemplate {
709 get { return headerTemplate; }
710 set { headerTemplate = value; RequireBinding (); }
713 [LocalizableAttribute (true)]
\r
714 [WebCategoryAttribute ("Appearance")]
\r
715 [DefaultValueAttribute ("")]
\r
716 public virtual string HeaderText {
718 object ob = ViewState ["HeaderText"];
719 if (ob != null) return (string) ob;
723 ViewState ["HeaderText"] = value;
728 [Category ("Layout")]
729 [DefaultValueAttribute (HorizontalAlign.NotSet)]
730 public virtual HorizontalAlign HorizontalAlign {
732 object ob = ViewState ["HorizontalAlign"];
733 if (ob != null) return (HorizontalAlign) ob;
734 return HorizontalAlign.NotSet;
737 ViewState ["HorizontalAlign"] = value;
742 [WebCategoryAttribute ("Styles")]
743 [PersistenceMode (PersistenceMode.InnerProperty)]
744 [NotifyParentProperty (true)]
745 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
746 [DefaultValueAttribute (null)]
\r
747 public TableItemStyle InsertRowStyle {
749 if (insertRowStyle == null) {
750 insertRowStyle = new TableItemStyle ();
751 if (IsTrackingViewState)
752 insertRowStyle.TrackViewState();
754 return insertRowStyle;
758 [BrowsableAttribute (false)]
759 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
760 public virtual int PageCount {
762 if (pageCount != 0) return pageCount;
768 [WebCategoryAttribute ("Paging")]
769 [BindableAttribute (true, BindingDirection.OneWay)]
\r
770 [DefaultValueAttribute (0)]
771 public virtual int PageIndex {
781 [WebCategoryAttribute ("Paging")]
782 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
783 [NotifyParentPropertyAttribute (true)]
784 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
785 public virtual PagerSettings PagerSettings {
787 if (pagerSettings == null) {
788 pagerSettings = new PagerSettings (this);
789 if (IsTrackingViewState)
790 ((IStateManager)pagerSettings).TrackViewState ();
792 return pagerSettings;
796 [WebCategoryAttribute ("Styles")]
797 [PersistenceMode (PersistenceMode.InnerProperty)]
798 [NotifyParentProperty (true)]
799 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
800 public TableItemStyle PagerStyle {
802 if (pagerStyle == null) {
803 pagerStyle = new TableItemStyle ();
804 if (IsTrackingViewState)
805 pagerStyle.TrackViewState();
812 [DefaultValue (null)]
813 /* DataControlPagerCell isnt specified in the docs */
814 //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
815 [PersistenceMode (PersistenceMode.InnerProperty)]
817 public virtual ITemplate PagerTemplate {
818 get { return pagerTemplate; }
819 set { pagerTemplate = value; RequireBinding (); }
822 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
823 [BrowsableAttribute (false)]
824 public virtual DetailsViewRowCollection Rows {
826 EnsureChildControls ();
831 [WebCategoryAttribute ("Styles")]
832 [PersistenceMode (PersistenceMode.InnerProperty)]
833 [NotifyParentProperty (true)]
834 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
835 [DefaultValue (null)]
836 public TableItemStyle RowStyle {
838 if (rowStyle == null) {
839 rowStyle = new TableItemStyle ();
840 if (IsTrackingViewState)
841 rowStyle.TrackViewState();
847 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
848 [BrowsableAttribute (false)]
849 public object SelectedValue {
850 get { return DataKey.Value; }
853 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
854 [BrowsableAttribute (false)]
855 public virtual DetailsViewRow TopPagerRow {
862 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
863 [BrowsableAttribute (false)]
864 public virtual object DataItem {
871 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
872 [BrowsableAttribute (false)]
873 public int DataItemCount {
874 get { return PageCount; }
877 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
878 [BrowsableAttribute (false)]
879 public virtual int DataItemIndex {
880 get { return PageIndex; }
883 int IDataItemContainer.DisplayIndex {
884 get { return PageIndex; }
887 public virtual bool IsBindableType (Type type)
889 return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Guid);
892 protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
894 return base.CreateDataSourceSelectArguments ();
897 protected virtual ICollection CreateFieldSet (object dataItem, bool useDataSource)
899 ArrayList fields = new ArrayList ();
901 if (AutoGenerateRows) {
903 if (dataItem != null)
904 fields.AddRange (CreateAutoGeneratedRows (dataItem));
906 if (autoFieldProperties != null) {
907 foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
908 fields.Add (CreateAutoGeneratedRow (props));
913 fields.AddRange (Fields);
915 if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateInsertButton) {
916 CommandField field = new CommandField ();
917 field.ShowEditButton = AutoGenerateEditButton;
918 field.ShowDeleteButton = AutoGenerateDeleteButton;
919 field.ShowInsertButton = AutoGenerateInsertButton;
921 commandField = field;
927 protected virtual ICollection CreateAutoGeneratedRows (object dataItem)
929 ArrayList list = new ArrayList ();
930 autoFieldProperties = CreateAutoFieldProperties (dataItem);
931 foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
932 list.Add (CreateAutoGeneratedRow (props));
936 protected virtual AutoGeneratedField CreateAutoGeneratedRow (AutoGeneratedFieldProperties fieldProperties)
938 return new AutoGeneratedField (fieldProperties);
941 AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
943 PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
945 ArrayList retVal = new ArrayList();
946 if (props != null && props.Count > 0)
948 foreach (PropertyDescriptor current in props) {
949 if (IsBindableType (current.PropertyType)) {
950 AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
951 ((IStateManager)field).TrackViewState();
952 field.Name = current.Name;
953 field.DataField = current.Name;
954 field.IsReadOnly = current.IsReadOnly;
955 field.Type = current.PropertyType;
961 if (retVal.Count > 0)
962 return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
964 return new AutoGeneratedFieldProperties [0];
967 protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
970 if (rowType == DataControlRowType.Pager)
971 row = new DetailsViewPagerRow (rowIndex, rowType, rowState);
973 row = new DetailsViewRow (rowIndex, rowType, rowState);
974 OnItemCreated (EventArgs.Empty);
978 void RequireBinding ()
981 RequiresDataBinding = true;
986 protected virtual Table CreateTable ()
988 Table table = new Table ();
989 table.Caption = Caption;
990 table.CaptionAlign = CaptionAlign;
991 table.CellPadding = CellPadding;
\r
992 //CellSpacing defaults to 0 and Table.CellSpacing to -1
\r
993 if (CellSpacing != 0)
\r
994 table.CellSpacing = CellSpacing;
995 table.HorizontalAlign = HorizontalAlign;
996 table.BackImageUrl = BackImageUrl;
1001 protected override Style CreateControlStyle ()
1003 return base.CreateControlStyle ();
1006 protected override int CreateChildControls (IEnumerable data, bool dataBinding)
1008 PagedDataSource dataSource;
1011 DataSourceView view = GetData ();
1012 dataSource = new PagedDataSource ();
1013 dataSource.DataSource = data;
1016 dataSource.AllowPaging = true;
1017 dataSource.PageSize = 1;
1018 dataSource.CurrentPageIndex = PageIndex;
1020 dataSource.AllowServerPaging = true;
1021 if (view.CanRetrieveTotalRowCount)
1022 dataSource.VirtualCount = SelectArguments.TotalRowCount;
1026 pageCount = dataSource.PageCount;
1030 dataSource = new PagedDataSource ();
1031 dataSource.DataSource = data;
1033 dataSource.AllowPaging = true;
1034 dataSource.PageSize = 1;
1035 dataSource.CurrentPageIndex = PageIndex;
1039 bool showPager = AllowPaging && (PageCount > 1);
1042 table = CreateTable ();
\r
1043 table.CellSpacing = CellSpacing;
1044 Controls.Add (table);
1046 ArrayList list = new ArrayList ();
\r
1048 if (Page == null || !Page.IsPostBack)
\r
1049 currentMode = DefaultMode;
1052 // Gets the current data item
1054 IEnumerator e = dataSource.GetEnumerator ();
1056 dataItem = e.Current;
1060 // Creates the set of fields to show
1062 ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding);
1063 DataControlField[] fields = new DataControlField [fieldCollection.Count];
1064 fieldCollection.CopyTo (fields, 0);
1066 foreach (DataControlField field in fields) {
1067 field.Initialize (false, this);
1068 if (EnablePagingCallbacks)
1069 field.ValidateSupportsCallback ();
1072 // Main table creation
1074 headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
1075 DataControlFieldCell headerCell = new DataControlFieldCell (null);
1076 headerCell.ColumnSpan = 2;
1077 if (headerTemplate != null)
1078 headerTemplate.InstantiateIn (headerCell);
1080 headerCell.Text = HeaderText;
1081 headerRow.Cells.Add (headerCell);
1082 table.Rows.Add (headerRow);
1084 if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
1085 topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
1086 InitializePager (topPagerRow, dataSource);
1087 table.Rows.Add (topPagerRow);
1090 if (dataSource.Count > 0) {
1091 foreach (DataControlField field in fields) {
1092 DataControlRowState rstate = GetRowState (list.Count);
1093 DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate);
1094 InitializeRow (row, field);
1095 table.Rows.Add (row);
1098 if (commandField == field)
1102 if (CurrentMode == DetailsViewMode.Edit)
1103 oldEditValues = new DataKey (new OrderedDictionary ());
1104 key = new DataKey (new OrderedDictionary (), DataKeyNames);
1107 table.Rows.Add (CreateEmptyrRow ());
1110 rows = new DetailsViewRowCollection (list);
1112 if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
1113 bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
1114 InitializePager (bottomPagerRow, dataSource);
1115 table.Rows.Add (bottomPagerRow);
1118 footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal);
1119 DataControlFieldCell footerCell = new DataControlFieldCell (null);
\r
1120 footerCell.ColumnSpan = 2;
1121 if (footerTemplate != null)
\r
1122 footerTemplate.InstantiateIn (footerCell);
1124 footerCell.Text = FooterText;
\r
1125 footerRow.Cells.Add (footerCell);
1126 table.Rows.Add (footerRow);
1131 return dataSource.DataSourceCount;
1135 protected override void EnsureDataBound ()
1137 base.EnsureDataBound ();
1140 DataControlRowState GetRowState (int index)
1142 DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
1143 if (CurrentMode == DetailsViewMode.Edit) rstate |= DataControlRowState.Edit;
1144 else if (CurrentMode == DetailsViewMode.Insert) rstate |= DataControlRowState.Insert;
1148 protected virtual void InitializePager (DetailsViewRow row, PagedDataSource dataSource)
1150 TableCell cell = new TableCell ();
1151 cell.ColumnSpan = 2;
1153 if (pagerTemplate != null)
1154 pagerTemplate.InstantiateIn (cell);
1156 cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
1158 row.Cells.Add (cell);
1161 DetailsViewRow CreateEmptyrRow ()
1163 DetailsViewRow row = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
1164 TableCell cell = new TableCell ();
1165 cell.ColumnSpan = 2;
1167 if (emptyDataTemplate != null)
1168 emptyDataTemplate.InstantiateIn (cell);
1170 cell.Text = EmptyDataText;
1172 row.Cells.Add (cell);
1176 protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
1178 DataControlFieldCell cell;
1180 if (field.ShowHeader) {
1181 cell = new DataControlFieldCell (field);
1182 row.Cells.Add (cell);
1183 field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
1186 cell = new DataControlFieldCell (field);
1187 if (!field.ShowHeader)
1188 cell.ColumnSpan = 2;
1189 row.Cells.Add (cell);
1190 field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);
1193 IOrderedDictionary CreateRowDataKey (object dataItem)
1195 if (cachedKeyProperties == null) {
1196 PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
1197 cachedKeyProperties = new PropertyDescriptor [DataKeyNames.Length];
1198 for (int n=0; n<DataKeyNames.Length; n++) {
1199 PropertyDescriptor p = props [DataKeyNames[n]];
1201 new InvalidOperationException ("Property '" + DataKeyNames[n] + "' not found in object of type " + dataItem.GetType());
1202 cachedKeyProperties [n] = p;
1206 OrderedDictionary dic = new OrderedDictionary ();
1207 foreach (PropertyDescriptor p in cachedKeyProperties)
1208 dic [p.Name] = p.GetValue (dataItem);
1212 IOrderedDictionary GetRowValues (bool includeReadOnlyFields, bool includePrimaryKey)
1214 OrderedDictionary dic = new OrderedDictionary ();
1215 ExtractRowValues (dic, includeReadOnlyFields, includePrimaryKey);
1219 protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, bool includeReadOnlyFields, bool includePrimaryKey)
1221 foreach (DetailsViewRow row in Rows) {
1222 if (row.Cells.Count < 1) continue;
1223 DataControlFieldCell c = row.Cells[row.Cells.Count-1] as DataControlFieldCell;
1225 c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
1227 if (!includePrimaryKey && DataKeyNames != null)
1228 foreach (string key in DataKeyNames)
1229 fieldValues.Remove (key);
1232 protected override HtmlTextWriterTag TagKey {
1234 if (EnablePagingCallbacks)
1235 return HtmlTextWriterTag.Div;
1237 return HtmlTextWriterTag.Table;
1241 public sealed override void DataBind ()
1243 DataSourceView view = GetData ();
1244 if (AllowPaging && view.CanPage) {
1245 SelectArguments.StartRowIndex = PageIndex;
1246 SelectArguments.MaximumRows = 1;
1247 if (view.CanRetrieveTotalRowCount)
1248 SelectArguments.RetrieveTotalRowCount = true;
1251 cachedKeyProperties = null;
1254 if (dataItem != null) {
1255 if (CurrentMode == DetailsViewMode.Edit)
1256 oldEditValues = new DataKey (GetRowValues (false, true));
1257 key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
1261 protected internal override void PerformDataBinding (IEnumerable data)
1263 base.PerformDataBinding (data);
1267 protected internal virtual void PrepareControlHierarchy ()
1269 throw new NotImplementedException ();
1272 protected internal override void OnInit (EventArgs e)
1274 Page.RegisterRequiresControlState (this);
1278 void OnFieldsChanged (object sender, EventArgs args)
1283 protected override void OnDataSourceViewChanged (object sender, EventArgs e)
1285 base.OnDataSourceViewChanged (sender, e);
1289 protected override bool OnBubbleEvent (object source, EventArgs e)
1291 DetailsViewCommandEventArgs args = e as DetailsViewCommandEventArgs;
1293 OnItemCommand (args);
1294 ProcessEvent (args.CommandName, args.CommandArgument as string);
1296 return base.OnBubbleEvent (source, e);
1299 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
1301 RaisePostBackEvent (eventArgument);
1304 // TODO: This is prolly obsolete
1305 protected virtual void RaisePostBackEvent (string eventArgument)
1307 int i = eventArgument.IndexOf ('$');
1309 ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
1311 ProcessEvent (eventArgument, null);
1314 void ProcessEvent (string eventName, string param)
1318 case DataControlCommands.PageCommandName:
1321 case DataControlCommands.FirstPageCommandArgument:
1324 case DataControlCommands.LastPageCommandArgument:
1325 newIndex = PageCount - 1;
1327 case DataControlCommands.NextPageCommandArgument:
1328 if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
1330 case DataControlCommands.PreviousPageCommandArgument:
1331 if (PageIndex > 0) newIndex = PageIndex - 1;
1334 newIndex = int.Parse (param) - 1;
1337 ShowPage (newIndex);
1340 case DataControlCommands.FirstPageCommandArgument:
1344 case DataControlCommands.LastPageCommandArgument:
1345 ShowPage (PageCount - 1);
1348 case DataControlCommands.NextPageCommandArgument:
1349 if (PageIndex < PageCount - 1)
1350 ShowPage (PageIndex + 1);
1353 case DataControlCommands.PreviousPageCommandArgument:
1355 ShowPage (PageIndex - 1);
1358 case DataControlCommands.EditCommandName:
1359 ChangeMode (DetailsViewMode.Edit);
1362 case DataControlCommands.NewCommandName:
1363 ChangeMode (DetailsViewMode.Insert);
1366 case DataControlCommands.UpdateCommandName:
1367 UpdateItem (param, true);
1370 case DataControlCommands.CancelCommandName:
1374 case DataControlCommands.DeleteCommandName:
1378 case DataControlCommands.InsertCommandName:
1384 void ShowPage (int newIndex)
1386 DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
1387 OnPageIndexChanging (args);
1390 PageIndex = args.NewPageIndex;
1391 OnPageIndexChanged (EventArgs.Empty);
1395 public void ChangeMode (DetailsViewMode newMode)
1397 DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
1398 OnModeChanging (args);
1400 currentMode = args.NewMode;
1401 OnModeChanged (EventArgs.Empty);
1408 DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
1409 OnModeChanging (args);
1415 public virtual void UpdateItem (bool causesValidation)
1417 UpdateItem (null, causesValidation);
1420 void UpdateItem (string param, bool causesValidation)
1422 if (causesValidation)
1425 if (currentMode != DetailsViewMode.Edit) throw new NotSupportedException ();
1427 currentEditOldValues = oldEditValues.Values;
1429 currentEditRowKeys = DataKey.Values;
1430 currentEditNewValues = GetRowValues (false, false);
1432 DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
1433 OnItemUpdating (args);
1435 DataSourceView view = GetData ();
1436 if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
1437 view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
1442 bool UpdateCallback (int recordsAffected, Exception exception)
1444 DetailsViewUpdatedEventArgs dargs = new DetailsViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
1445 OnItemUpdated (dargs);
1447 if (!dargs.KeepInEditMode)
1450 return dargs.ExceptionHandled;
1453 public virtual void InsertItem (bool causesValidation)
1455 InsertItem (null, causesValidation);
1458 void InsertItem (string param, bool causesValidation)
1460 if (causesValidation)
1463 if (currentMode != DetailsViewMode.Insert) throw new NotSupportedException ();
1465 currentEditNewValues = GetRowValues (false, true);
1466 DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
1467 OnItemInserting (args);
1469 DataSourceView view = GetData ();
1470 if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
1471 view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
1476 bool InsertCallback (int recordsAffected, Exception exception)
1478 DetailsViewInsertedEventArgs dargs = new DetailsViewInsertedEventArgs (recordsAffected, exception, currentEditNewValues);
1479 OnItemInserted (dargs);
1481 if (!dargs.KeepInInsertMode)
1484 return dargs.ExceptionHandled;
1487 public virtual void DeleteItem ()
1489 currentEditRowKeys = DataKey == null ? null : DataKey.Values;
1490 currentEditNewValues = GetRowValues (true, true);
1492 DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
1493 OnItemDeleting (args);
1496 if (PageIndex == PageCount - 1)
1499 DataSourceView view = GetData ();
1501 view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
1503 DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
1504 OnItemDeleted (dargs);
1509 bool DeleteCallback (int recordsAffected, Exception exception)
1511 DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
1512 OnItemDeleted (dargs);
1513 return dargs.ExceptionHandled;
1518 ChangeMode (DefaultMode);
1519 oldEditValues = new DataKey (new OrderedDictionary ());
1520 currentEditRowKeys = null;
1521 currentEditOldValues = null;
1522 currentEditNewValues = null;
1526 protected internal override void LoadControlState (object ob)
1528 if (ob == null) return;
1529 object[] state = (object[]) ob;
1530 base.LoadControlState (state[0]);
1531 pageIndex = (int) state[1];
1532 pageCount = (int) state[2];
1533 currentMode = (DetailsViewMode) state[3];
1536 protected internal override object SaveControlState ()
1538 object bstate = base.SaveControlState ();
1539 return new object[] {
1540 bstate, pageIndex, pageCount, currentMode
1544 protected override void TrackViewState()
1546 base.TrackViewState();
1547 if (columns != null) ((IStateManager)columns).TrackViewState();
1548 if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
1549 if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
1550 if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
1551 if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1552 if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
1553 if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
1554 if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
1555 if (insertRowStyle != null) ((IStateManager)insertRowStyle).TrackViewState();
1556 if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
1557 if (key != null) ((IStateManager)key).TrackViewState();
1558 if (autoFieldProperties != null) {
1559 foreach (IStateManager sm in autoFieldProperties)
1560 sm.TrackViewState ();
1564 protected override object SaveViewState()
1566 object[] states = new object [14];
1567 states[0] = base.SaveViewState();
1568 states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
1569 states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
1570 states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
1571 states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
1572 states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
1573 states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
1574 states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
1575 states[8] = (insertRowStyle == null ? null : ((IStateManager)insertRowStyle).SaveViewState());
1576 states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
1577 states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
1578 states[11] = (key == null ? null : ((IStateManager)key).SaveViewState());
1579 states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
1581 if (autoFieldProperties != null) {
1582 object[] data = new object [autoFieldProperties.Length];
1583 bool allNull = true;
1584 for (int n=0; n<data.Length; n++) {
1585 data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
1586 if (data [n] != null) allNull = false;
1588 if (!allNull) states [13] = data;
1591 for (int i = states.Length - 1; i >= 0; i--) {
1592 if (states [i] != null)
1599 protected override void LoadViewState (object savedState)
1601 if (savedState == null) {
1602 base.LoadViewState (null);
1606 object [] states = (object []) savedState;
1608 if (states[13] != null) {
1609 object[] data = (object[]) states [13];
1610 autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
1611 for (int n=0; n<data.Length; n++) {
1612 IStateManager p = new AutoGeneratedFieldProperties ();
1613 p.TrackViewState ();
1614 p.LoadViewState (data [n]);
1615 autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
1619 base.LoadViewState (states[0]);
1620 EnsureChildControls ();
1622 if (states[1] != null) ((IStateManager)Fields).LoadViewState (states[1]);
1623 if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
1624 if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
1625 if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
1626 if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
1627 if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
1628 if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
1629 if (states[8] != null) ((IStateManager)InsertRowStyle).LoadViewState (states[8]);
1630 if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
1631 if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
1632 if (states[11] != null) ((IStateManager)DataKey).LoadViewState (states[11]);
1633 if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
1636 void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
1638 RaiseCallbackEvent (eventArgs);
1641 string callbackResult;
1642 protected virtual void RaiseCallbackEvent (string eventArgs)
1644 string[] clientData = eventArgs.Split ('|');
1645 pageIndex = int.Parse (clientData[0]);
1648 RaisePostBackEvent (clientData[2]);
1651 StringWriter sw = new StringWriter ();
1652 sw.Write (PageIndex.ToString());
1654 HtmlTextWriter writer = new HtmlTextWriter (sw);
1655 RenderGrid (writer);
1656 callbackResult = sw.ToString ();
1659 string ICallbackEventHandler.GetCallbackResult ()
1661 return GetCallbackResult ();
1664 protected virtual string GetCallbackResult ()
1666 return callbackResult;
1670 protected virtual string GetCallbackScript (IButtonControl buttonControl, string argument)
1672 throw new NotImplementedException ();
1675 string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
1677 if (EnablePagingCallbacks)
1678 return "javascript:GridView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
1684 protected override void OnPagePreLoad (object sender, EventArgs e)
1686 base.OnPagePreLoad (sender, e);
1689 protected internal override void OnPreRender (EventArgs e)
1691 base.OnPreRender (e);
1693 if (EnablePagingCallbacks)
1695 if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(GridView), "GridView.js")) {
1696 string url = Page.ClientScript.GetWebResourceUrl (typeof(GridView), "GridView.js");
1697 Page.ClientScript.RegisterClientScriptInclude (typeof(GridView), "GridView.js", url);
1700 string cgrid = ClientID + "_data";
1701 string script = string.Format ("var {0} = new Object ();\n", cgrid);
1702 script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
1703 script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
1704 Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
1706 // Make sure the basic script infrastructure is rendered
1707 Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
1708 Page.ClientScript.GetPostBackClientHyperlink (this, "");
1712 protected internal override void Render (HtmlTextWriter writer)
1714 if (EnablePagingCallbacks)
1715 base.RenderBeginTag (writer);
\r
1717 writer.RenderBeginTag (HtmlTextWriterTag.Div);
1719 RenderGrid (writer);
1721 if (EnablePagingCallbacks)
1722 base.RenderEndTag (writer);
\r
1724 writer.RenderEndTag ();
1727 void RenderGrid (HtmlTextWriter writer)
1729 table.GridLines = GridLines;
\r
1730 table.ControlStyle.MergeWith (ControlStyle);
\r
1731 table.RenderBeginTag (writer);
1733 foreach (DetailsViewRow row in table.Rows)
1735 switch (row.RowType) {
1736 case DataControlRowType.Header:
1737 if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
1739 case DataControlRowType.Footer:
1740 if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
1742 case DataControlRowType.Pager:
1743 if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
1745 case DataControlRowType.EmptyDataRow:
1746 if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
1749 if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
1753 if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
1754 alternatingRowStyle.AddAttributesToRender (writer, row);
1755 if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
1756 editRowStyle.AddAttributesToRender (writer, row);
1757 if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null)
1758 insertRowStyle.AddAttributesToRender (writer, row);
1760 if (row == commandRow && commandRowStyle != null)
1761 commandRowStyle.AddAttributesToRender (writer, row);
1763 row.RenderBeginTag (writer);
1765 for (int n=0; n<row.Cells.Count; n++) {
1766 DataControlFieldCell fcell = row.Cells[n] as DataControlFieldCell;
1767 if (fcell != null && fcell.ContainingField != null) {
1768 if (n == 0 && fcell.ContainingField.ShowHeader) {
1769 if (fieldHeaderStyle != null)
1770 fieldHeaderStyle.AddAttributesToRender (writer, fcell);
1771 fcell.ContainingField.HeaderStyle.AddAttributesToRender (writer, fcell);
1774 fcell.ContainingField.ItemStyle.AddAttributesToRender (writer, fcell);
1776 row.Cells[n].Render (writer);
1778 row.RenderEndTag (writer);
1780 table.RenderEndTag (writer);
1785 PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
1787 PostBackOptions pbo = new PostBackOptions (this, control.CommandName + "$" + control.CommandArgument);
\r