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 [ToolboxDataAttribute ("<{0}:DetailsView runat=\"server\" Width=\"125px\" Height=\"50px\"></{0}:DetailsView>")]
\r
44 [DesignerAttribute ("System.Web.UI.Design.WebControls.DetailsViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45 [ControlValuePropertyAttribute ("SelectedValue")]
46 [DefaultEventAttribute ("PageIndexChanging")]
47 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
48 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
49 public class DetailsView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IDataItemContainer, INamingContainer
54 DetailsViewRowCollection rows;
55 DetailsViewRow headerRow;
56 DetailsViewRow footerRow;
57 DetailsViewRow bottomPagerRow;
58 DetailsViewRow topPagerRow;
60 IOrderedDictionary currentEditRowKeys;
61 IOrderedDictionary currentEditNewValues;
62 IOrderedDictionary currentEditOldValues;
64 ITemplate pagerTemplate;
65 ITemplate emptyDataTemplate;
66 ITemplate headerTemplate;
67 ITemplate footerTemplate;
69 PropertyDescriptor[] cachedKeyProperties;
70 readonly string[] emptyKeys = new string[0];
72 CommandField commandField;
73 DetailsViewRow commandRow;
76 DataControlFieldCollection columns;
77 PagerSettings pagerSettings;
79 TableItemStyle alternatingRowStyle;
80 TableItemStyle editRowStyle;
81 TableItemStyle insertRowStyle;
82 TableItemStyle emptyDataRowStyle;
83 TableItemStyle footerStyle;
84 TableItemStyle headerStyle;
85 TableItemStyle pagerStyle;
86 TableItemStyle rowStyle;
87 TableItemStyle commandRowStyle;
88 TableItemStyle fieldHeaderStyle;
91 DataKey oldEditValues;
92 AutoGeneratedFieldProperties[] autoFieldProperties;
94 private static readonly object PageIndexChangedEvent = new object();
95 private static readonly object PageIndexChangingEvent = new object();
96 private static readonly object ItemCommandEvent = new object();
97 private static readonly object ItemCreatedEvent = new object();
98 private static readonly object ItemDeletedEvent = new object();
99 private static readonly object ItemDeletingEvent = new object();
100 private static readonly object ItemInsertedEvent = new object();
101 private static readonly object ItemInsertingEvent = new object();
102 private static readonly object ModeChangingEvent = new object();
103 private static readonly object ModeChangedEvent = new object();
104 private static readonly object ItemUpdatedEvent = new object();
105 private static readonly object ItemUpdatingEvent = new object();
109 DetailsViewMode currentMode = DetailsViewMode.ReadOnly;
112 public DetailsView ()
116 public event EventHandler PageIndexChanged {
117 add { Events.AddHandler (PageIndexChangedEvent, value); }
118 remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
121 public event DetailsViewPageEventHandler PageIndexChanging {
122 add { Events.AddHandler (PageIndexChangingEvent, value); }
123 remove { Events.RemoveHandler (PageIndexChangingEvent, value); }
126 public event DetailsViewCommandEventHandler ItemCommand {
127 add { Events.AddHandler (ItemCommandEvent, value); }
128 remove { Events.RemoveHandler (ItemCommandEvent, value); }
131 public event EventHandler ItemCreated {
132 add { Events.AddHandler (ItemCreatedEvent, value); }
133 remove { Events.RemoveHandler (ItemCreatedEvent, value); }
136 public event DetailsViewDeletedEventHandler ItemDeleted {
137 add { Events.AddHandler (ItemDeletedEvent, value); }
138 remove { Events.RemoveHandler (ItemDeletedEvent, value); }
141 public event DetailsViewDeleteEventHandler ItemDeleting {
142 add { Events.AddHandler (ItemDeletingEvent, value); }
143 remove { Events.RemoveHandler (ItemDeletingEvent, value); }
146 public event DetailsViewInsertedEventHandler ItemInserted {
147 add { Events.AddHandler (ItemInsertedEvent, value); }
148 remove { Events.RemoveHandler (ItemInsertedEvent, value); }
151 public event DetailsViewInsertEventHandler ItemInserting {
152 add { Events.AddHandler (ItemInsertingEvent, value); }
153 remove { Events.RemoveHandler (ItemInsertingEvent, value); }
156 public event DetailsViewModeEventHandler ModeChanging {
157 add { Events.AddHandler (ModeChangingEvent, value); }
158 remove { Events.RemoveHandler (ModeChangingEvent, value); }
161 public event EventHandler ModeChanged {
162 add { Events.AddHandler (ModeChangedEvent, value); }
163 remove { Events.RemoveHandler (ModeChangedEvent, value); }
166 public event DetailsViewUpdatedEventHandler ItemUpdated {
167 add { Events.AddHandler (ItemUpdatedEvent, value); }
168 remove { Events.RemoveHandler (ItemUpdatedEvent, value); }
171 public event DetailsViewUpdateEventHandler ItemUpdating {
172 add { Events.AddHandler (ItemUpdatingEvent, value); }
173 remove { Events.RemoveHandler (ItemUpdatingEvent, value); }
176 protected virtual void OnPageIndexChanged (EventArgs e)
178 if (Events != null) {
179 EventHandler eh = (EventHandler) Events [PageIndexChangedEvent];
180 if (eh != null) eh (this, e);
184 protected virtual void OnPageIndexChanging (DetailsViewPageEventArgs e)
186 if (Events != null) {
187 DetailsViewPageEventHandler eh = (DetailsViewPageEventHandler) Events [PageIndexChangingEvent];
188 if (eh != null) eh (this, e);
192 protected virtual void OnItemCommand (DetailsViewCommandEventArgs e)
194 if (Events != null) {
195 DetailsViewCommandEventHandler eh = (DetailsViewCommandEventHandler) Events [ItemCommandEvent];
196 if (eh != null) eh (this, e);
200 protected virtual void OnItemCreated (EventArgs e)
202 if (Events != null) {
203 EventHandler eh = (EventHandler) Events [ItemCreatedEvent];
204 if (eh != null) eh (this, e);
208 protected virtual void OnItemDeleted (DetailsViewDeletedEventArgs e)
210 if (Events != null) {
211 DetailsViewDeletedEventHandler eh = (DetailsViewDeletedEventHandler) Events [ItemDeletedEvent];
212 if (eh != null) eh (this, e);
216 protected virtual void OnItemInserted (DetailsViewInsertedEventArgs e)
218 if (Events != null) {
219 DetailsViewInsertedEventHandler eh = (DetailsViewInsertedEventHandler) Events [ItemInsertedEvent];
220 if (eh != null) eh (this, e);
224 protected virtual void OnItemInserting (DetailsViewInsertEventArgs e)
226 if (Events != null) {
227 DetailsViewInsertEventHandler eh = (DetailsViewInsertEventHandler) Events [ItemInsertingEvent];
228 if (eh != null) eh (this, e);
232 protected virtual void OnItemDeleting (DetailsViewDeleteEventArgs e)
234 if (Events != null) {
235 DetailsViewDeleteEventHandler eh = (DetailsViewDeleteEventHandler) Events [ItemDeletingEvent];
236 if (eh != null) eh (this, e);
240 protected virtual void OnModeChanged (EventArgs e)
242 if (Events != null) {
243 EventHandler eh = (EventHandler) Events [ModeChangedEvent];
244 if (eh != null) eh (this, e);
248 protected virtual void OnModeChanging (DetailsViewModeEventArgs e)
250 if (Events != null) {
251 DetailsViewModeEventHandler eh = (DetailsViewModeEventHandler) Events [ModeChangingEvent];
252 if (eh != null) eh (this, e);
256 protected virtual void OnItemUpdated (DetailsViewUpdatedEventArgs e)
258 if (Events != null) {
259 DetailsViewUpdatedEventHandler eh = (DetailsViewUpdatedEventHandler) Events [ItemUpdatedEvent];
260 if (eh != null) eh (this, e);
264 protected virtual void OnItemUpdating (DetailsViewUpdateEventArgs e)
266 if (Events != null) {
267 DetailsViewUpdateEventHandler eh = (DetailsViewUpdateEventHandler) Events [ItemUpdatingEvent];
268 if (eh != null) eh (this, e);
273 [WebCategoryAttribute ("Paging")]
274 [DefaultValueAttribute (false)]
275 public bool AllowPaging {
277 object ob = ViewState ["AllowPaging"];
278 if (ob != null) return (bool) ob;
282 ViewState ["AllowPaging"] = value;
287 [DefaultValueAttribute (null)]
288 [WebCategoryAttribute ("Styles")]
289 [PersistenceMode (PersistenceMode.InnerProperty)]
290 [NotifyParentProperty (true)]
291 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
292 public virtual TableItemStyle AlternatingRowStyle {
294 if (alternatingRowStyle == null) {
295 alternatingRowStyle = new TableItemStyle ();
296 if (IsTrackingViewState)
297 alternatingRowStyle.TrackViewState();
299 return alternatingRowStyle;
303 [WebCategoryAttribute ("Behavior")]
304 [DefaultValueAttribute (false)]
305 public virtual bool AutoGenerateEditButton {
307 object ob = ViewState ["AutoGenerateEditButton"];
308 if (ob != null) return (bool) ob;
312 ViewState ["AutoGenerateEditButton"] = value;
317 [WebCategoryAttribute ("Behavior")]
318 [DefaultValueAttribute (false)]
319 public virtual bool AutoGenerateDeleteButton {
321 object ob = ViewState ["AutoGenerateDeleteButton"];
322 if (ob != null) return (bool) ob;
326 ViewState ["AutoGenerateDeleteButton"] = value;
331 [WebCategoryAttribute ("Behavior")]
332 [DefaultValueAttribute (false)]
333 public virtual bool AutoGenerateInsertButton {
335 object ob = ViewState ["AutoGenerateInsertButton"];
336 if (ob != null) return (bool) ob;
340 ViewState ["AutoGenerateInsertButton"] = value;
345 [WebCategoryAttribute ("Behavior")]
346 [DefaultValueAttribute (true)]
347 public virtual bool AutoGenerateRows {
349 object ob = ViewState ["AutoGenerateRows"];
350 if (ob != null) return (bool) ob;
354 ViewState ["AutoGenerateRows"] = value;
359 [UrlPropertyAttribute]
360 [WebCategoryAttribute ("Appearance")]
361 [DefaultValueAttribute ("")]
362 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
363 public virtual string BackImageUrl {
365 object ob = ViewState ["BackImageUrl"];
366 if (ob != null) return (string) ob;
370 ViewState ["BackImageUrl"] = value;
375 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
376 [BrowsableAttribute (false)]
377 public virtual DetailsViewRow BottomPagerRow {
380 return bottomPagerRow;
384 [WebCategoryAttribute ("Accessibility")]
385 [DefaultValueAttribute ("")]
386 [LocalizableAttribute (true)]
387 public string Caption {
389 object ob = ViewState ["Caption"];
390 if (ob != null) return (string) ob;
394 ViewState ["Caption"] = value;
399 [WebCategoryAttribute ("Accessibility")]
400 [DefaultValueAttribute (TableCaptionAlign.NotSet)]
401 public virtual TableCaptionAlign CaptionAlign
404 object o = ViewState ["CaptionAlign"];
405 if(o != null) return (TableCaptionAlign) o;
406 return TableCaptionAlign.NotSet;
409 ViewState ["CaptionAlign"] = value;
414 [WebCategoryAttribute ("Layout")]
415 [DefaultValueAttribute (-1)]
416 public virtual int CellPadding
419 object o = ViewState ["CellPadding"];
420 if (o != null) return (int) o;
424 ViewState ["CellPadding"] = value;
429 [WebCategoryAttribute ("Layout")]
430 [DefaultValueAttribute (0)]
431 public virtual int CellSpacing
434 object o = ViewState ["CellSpacing"];
435 if (o != null) return (int) o;
439 ViewState ["CellSpacing"] = value;
444 [DefaultValueAttribute (null)]
445 [WebCategoryAttribute ("Styles")]
446 [PersistenceMode (PersistenceMode.InnerProperty)]
447 [NotifyParentProperty (true)]
448 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
449 public virtual TableItemStyle CommandRowStyle {
451 if (commandRowStyle == null) {
452 commandRowStyle = new TableItemStyle ();
453 if (IsTrackingViewState)
454 commandRowStyle.TrackViewState();
456 return commandRowStyle;
460 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
461 [BrowsableAttribute (false)]
\r
462 public DetailsViewMode CurrentMode {
468 [DefaultValueAttribute (DetailsViewMode.ReadOnly)]
\r
469 [WebCategoryAttribute ("Behavior")]
\r
470 public virtual DetailsViewMode DefaultMode {
472 object o = ViewState ["DefaultMode"];
473 if (o != null) return (DetailsViewMode) o;
474 return DetailsViewMode.ReadOnly;
477 ViewState ["DefaultMode"] = value;
482 [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
483 [MergablePropertyAttribute (false)]
484 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
485 [DefaultValueAttribute (null)]
486 [WebCategoryAttribute ("Misc")]
487 public virtual DataControlFieldCollection Fields {
489 if (columns == null) {
490 columns = new DataControlFieldCollection ();
491 columns.FieldsChanged += new EventHandler (OnFieldsChanged);
492 if (IsTrackingViewState)
493 ((IStateManager)columns).TrackViewState ();
499 [DefaultValueAttribute (null)]
500 [WebCategoryAttribute ("Data")]
501 [TypeConverter (typeof(StringArrayConverter))]
502 [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
503 public virtual string[] DataKeyNames
506 object o = ViewState ["DataKeyNames"];
507 if (o != null) return (string[]) o;
511 ViewState ["DataKeyNames"] = value;
516 [BrowsableAttribute (false)]
517 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
518 public virtual DataKey DataKey {
525 [WebCategoryAttribute ("Styles")]
526 [PersistenceMode (PersistenceMode.InnerProperty)]
527 [NotifyParentProperty (true)]
528 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
529 [DefaultValueAttribute (null)]
\r
530 public virtual TableItemStyle EditRowStyle {
532 if (editRowStyle == null) {
533 editRowStyle = new TableItemStyle ();
534 if (IsTrackingViewState)
535 editRowStyle.TrackViewState();
541 [WebCategoryAttribute ("Styles")]
542 [PersistenceMode (PersistenceMode.InnerProperty)]
543 [NotifyParentProperty (true)]
544 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
545 [DefaultValueAttribute (null)]
\r
546 public virtual TableItemStyle EmptyDataRowStyle {
548 if (emptyDataRowStyle == null) {
549 emptyDataRowStyle = new TableItemStyle ();
550 if (IsTrackingViewState)
551 emptyDataRowStyle.TrackViewState();
553 return emptyDataRowStyle;
557 [DefaultValue (null)]
558 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
559 [PersistenceMode (PersistenceMode.InnerProperty)]
561 public ITemplate EmptyDataTemplate {
562 get { return emptyDataTemplate; }
563 set { emptyDataTemplate = value; RequireBinding (); }
566 [LocalizableAttribute (true)]
567 [WebCategoryAttribute ("Appearance")]
568 [DefaultValueAttribute ("")]
569 public virtual string EmptyDataText {
571 object ob = ViewState ["EmptyDataText"];
572 if (ob != null) return (string) ob;
576 ViewState ["EmptyDataText"] = value;
581 [WebCategoryAttribute ("Behavior")]
582 [DefaultValueAttribute (false)]
583 public virtual bool EnablePagingCallbacks {
585 object ob = ViewState ["EnablePagingCallbacks"];
586 if (ob != null) return (bool) ob;
590 ViewState ["EnablePagingCallbacks"] = value;
595 [WebCategoryAttribute ("Styles")]
596 [PersistenceMode (PersistenceMode.InnerProperty)]
597 [NotifyParentProperty (true)]
598 [DefaultValue (null)]
599 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
600 public virtual TableItemStyle FieldHeaderStyle {
602 if (fieldHeaderStyle == null) {
603 fieldHeaderStyle = new TableItemStyle ();
604 if (IsTrackingViewState)
605 fieldHeaderStyle.TrackViewState();
607 return fieldHeaderStyle;
611 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
612 [BrowsableAttribute (false)]
613 public virtual DetailsViewRow FooterRow {
615 EnsureChildControls ();
620 [DefaultValue (null)]
621 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
622 [PersistenceMode (PersistenceMode.InnerProperty)]
624 public ITemplate FooterTemplate {
625 get { return footerTemplate; }
626 set { footerTemplate = value; RequireBinding (); }
629 [LocalizableAttribute (true)]
\r
630 [WebCategoryAttribute ("Appearance")]
\r
631 [DefaultValueAttribute ("")]
\r
632 public string FooterText {
634 object ob = ViewState ["FooterText"];
635 if (ob != null) return (string) ob;
639 ViewState ["FooterText"] = value;
644 [WebCategoryAttribute ("Styles")]
645 [PersistenceMode (PersistenceMode.InnerProperty)]
646 [NotifyParentProperty (true)]
647 [DefaultValue (null)]
648 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
649 public virtual TableItemStyle FooterStyle {
651 if (footerStyle == null) {
652 footerStyle = new TableItemStyle ();
653 if (IsTrackingViewState)
654 footerStyle.TrackViewState();
660 [WebCategoryAttribute ("Appearance")]
661 [DefaultValueAttribute (GridLines.Both)]
662 public virtual GridLines GridLines {
664 object ob = ViewState ["GridLines"];
665 if (ob != null) return (GridLines) ob;
666 return GridLines.Both;
669 ViewState ["GridLines"] = value;
673 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
674 [BrowsableAttribute (false)]
675 public virtual DetailsViewRow HeaderRow {
677 EnsureChildControls ();
682 [WebCategoryAttribute ("Styles")]
683 [PersistenceMode (PersistenceMode.InnerProperty)]
684 [NotifyParentProperty (true)]
685 [DefaultValue (null)]
686 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
687 public virtual TableItemStyle HeaderStyle {
689 if (headerStyle == null) {
690 headerStyle = new TableItemStyle ();
691 if (IsTrackingViewState)
692 headerStyle.TrackViewState();
698 [DefaultValue (null)]
699 [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
700 [PersistenceMode (PersistenceMode.InnerProperty)]
702 public ITemplate HeaderTemplate {
703 get { return headerTemplate; }
704 set { headerTemplate = value; RequireBinding (); }
707 [LocalizableAttribute (true)]
\r
708 [WebCategoryAttribute ("Appearance")]
\r
709 [DefaultValueAttribute ("")]
\r
710 public string HeaderText {
712 object ob = ViewState ["HeaderText"];
713 if (ob != null) return (string) ob;
717 ViewState ["HeaderText"] = value;
722 [Category ("Layout")]
723 [DefaultValueAttribute (HorizontalAlign.NotSet)]
724 public virtual HorizontalAlign HorizontalAlign {
726 object ob = ViewState ["HorizontalAlign"];
727 if (ob != null) return (HorizontalAlign) ob;
728 return HorizontalAlign.NotSet;
731 ViewState ["HorizontalAlign"] = value;
736 [WebCategoryAttribute ("Styles")]
737 [PersistenceMode (PersistenceMode.InnerProperty)]
738 [NotifyParentProperty (true)]
739 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
740 [DefaultValueAttribute (null)]
\r
741 public virtual TableItemStyle InsertRowStyle {
743 if (insertRowStyle == null) {
744 insertRowStyle = new TableItemStyle ();
745 if (IsTrackingViewState)
746 insertRowStyle.TrackViewState();
748 return insertRowStyle;
752 [BrowsableAttribute (false)]
753 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
754 public int PageCount {
756 if (pageCount != -1) return pageCount;
762 [WebCategoryAttribute ("Paging")]
763 [BindableAttribute (true, BindingDirection.OneWay)]
\r
764 [DefaultValueAttribute (0)]
765 public int PageIndex {
775 [WebCategoryAttribute ("Paging")]
776 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
777 [NotifyParentPropertyAttribute (true)]
778 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
779 public PagerSettings PagerSettings {
781 if (pagerSettings == null) {
782 pagerSettings = new PagerSettings (this);
783 if (IsTrackingViewState)
784 ((IStateManager)pagerSettings).TrackViewState ();
786 return pagerSettings;
790 [WebCategoryAttribute ("Styles")]
791 [PersistenceMode (PersistenceMode.InnerProperty)]
792 [NotifyParentProperty (true)]
793 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
794 public virtual TableItemStyle PagerStyle {
796 if (pagerStyle == null) {
797 pagerStyle = new TableItemStyle ();
798 if (IsTrackingViewState)
799 pagerStyle.TrackViewState();
806 [DefaultValue (null)]
807 /* DataControlPagerCell isnt specified in the docs */
808 //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
809 [PersistenceMode (PersistenceMode.InnerProperty)]
811 public ITemplate PagerTemplate {
812 get { return pagerTemplate; }
813 set { pagerTemplate = value; RequireBinding (); }
816 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
817 [BrowsableAttribute (false)]
818 public virtual DetailsViewRowCollection Rows {
825 [WebCategoryAttribute ("Styles")]
826 [PersistenceMode (PersistenceMode.InnerProperty)]
827 [NotifyParentProperty (true)]
828 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
829 [DefaultValue (null)]
830 public virtual TableItemStyle RowStyle {
832 if (rowStyle == null) {
833 rowStyle = new TableItemStyle ();
834 if (IsTrackingViewState)
835 rowStyle.TrackViewState();
841 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
842 [BrowsableAttribute (false)]
843 public virtual object SelectedValue {
844 get { return DataKey.Value; }
847 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
848 [BrowsableAttribute (false)]
849 public virtual DetailsViewRow TopPagerRow {
856 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
857 [BrowsableAttribute (false)]
858 public object DataItem {
865 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
866 [BrowsableAttribute (false)]
867 public int DataItemCount {
868 get { return PageCount; }
871 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
872 [BrowsableAttribute (false)]
873 public int DataItemIndex {
874 get { return PageIndex; }
877 int IDataItemContainer.DisplayIndex {
878 get { return PageIndex; }
881 public virtual bool IsBindableType (Type type)
883 return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Guid);
886 protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
888 return base.CreateDataSourceSelectArguments ();
891 protected virtual ICollection CreateFieldSet (object dataItem, bool useDataSource)
893 ArrayList fields = new ArrayList ();
895 if (AutoGenerateRows) {
897 if (dataItem != null)
898 fields.AddRange (CreateAutoGeneratedRows (dataItem));
900 if (autoFieldProperties != null) {
901 foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
902 fields.Add (CreateAutoGeneratedRow (props));
907 fields.AddRange (Fields);
909 if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateInsertButton) {
910 CommandField field = new CommandField ();
911 field.ShowEditButton = AutoGenerateEditButton;
912 field.ShowDeleteButton = AutoGenerateDeleteButton;
913 field.ShowInsertButton = AutoGenerateInsertButton;
915 commandField = field;
921 protected virtual ICollection CreateAutoGeneratedRows (object dataItem)
923 ArrayList list = new ArrayList ();
924 autoFieldProperties = CreateAutoFieldProperties (dataItem);
925 foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
926 list.Add (CreateAutoGeneratedRow (props));
930 protected virtual AutoGeneratedField CreateAutoGeneratedRow (AutoGeneratedFieldProperties fieldProperties)
932 return new AutoGeneratedField (fieldProperties);
935 AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
937 PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
939 ArrayList retVal = new ArrayList();
940 if (props != null && props.Count > 0)
942 foreach (PropertyDescriptor current in props) {
943 if (IsBindableType (current.PropertyType)) {
944 AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
945 ((IStateManager)field).TrackViewState();
946 field.Name = current.Name;
947 field.DataField = current.Name;
948 field.IsReadOnly = current.IsReadOnly;
949 field.Type = current.PropertyType;
955 if (retVal.Count > 0)
956 return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
958 return new AutoGeneratedFieldProperties [0];
961 protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
963 DetailsViewRow row = new DetailsViewRow (rowIndex, rowType, rowState);
964 OnItemCreated (EventArgs.Empty);
968 void RequireBinding ()
971 RequiresDataBinding = true;
976 protected virtual Table CreateTable ()
978 Table table = new Table ();
979 table.Caption = Caption;
980 table.CaptionAlign = CaptionAlign;
981 table.CellPadding = CellPadding;
982 table.CellSpacing = CellSpacing;
983 table.HorizontalAlign = HorizontalAlign;
984 table.BackImageUrl = BackImageUrl;
989 protected override Style CreateControlStyle ()
991 throw new NotImplementedException ();
994 protected override int CreateChildControls (IEnumerable data, bool dataBinding)
996 PagedDataSource dataSource;
999 DataSourceView view = GetData ();
1000 dataSource = new PagedDataSource ();
1001 dataSource.DataSource = data;
1004 dataSource.AllowPaging = true;
1005 dataSource.PageSize = 1;
1006 dataSource.CurrentPageIndex = PageIndex;
1008 dataSource.AllowServerPaging = true;
1009 if (view.CanRetrieveTotalRowCount)
1010 dataSource.VirtualCount = SelectArguments.TotalRowCount;
1012 dataSource.DataSourceView = view;
1013 dataSource.DataSourceSelectArguments = SelectArguments;
1014 dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount);
1019 pageCount = dataSource.PageCount;
1023 dataSource = new PagedDataSource ();
1024 dataSource.DataSource = data;
1026 dataSource.AllowPaging = true;
1027 dataSource.PageSize = 1;
1028 dataSource.CurrentPageIndex = PageIndex;
1032 bool showPager = AllowPaging && (PageCount > 1);
1035 table = CreateTable ();
1036 Controls.Add (table);
1038 ArrayList list = new ArrayList ();
1040 if (!Page.IsPostBack)
1041 currentMode = DefaultMode;
1044 // Gets the current data item
1046 IEnumerator e = dataSource.GetEnumerator ();
1048 dataItem = e.Current;
1052 // Creates the set of fields to show
1054 ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding);
1055 DataControlField[] fields = new DataControlField [fieldCollection.Count];
1056 fieldCollection.CopyTo (fields, 0);
1058 foreach (DataControlField field in fields) {
1059 field.Initialize (false, this);
1060 if (EnablePagingCallbacks)
1061 field.ValidateSupportsCallback ();
1064 // Main table creation
1066 if (HeaderText.Length != 0 || headerTemplate != null) {
1067 headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
1068 DataControlFieldCell cell = new DataControlFieldCell (null);
1069 cell.ColumnSpan = 2;
1070 if (headerTemplate != null)
1071 headerTemplate.InstantiateIn (cell);
1073 cell.Text = HeaderText;
1074 headerRow.Cells.Add (cell);
1075 table.Rows.Add (headerRow);
1078 if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
1079 topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
1080 InitializePager (topPagerRow, dataSource);
1081 table.Rows.Add (topPagerRow);
1084 if (dataSource.Count > 0) {
1085 foreach (DataControlField field in fields) {
1086 DataControlRowState rstate = GetRowState (list.Count);
1087 DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate);
1088 InitializeRow (row, field);
1089 table.Rows.Add (row);
1092 if (commandField == field)
1096 if (CurrentMode == DetailsViewMode.Edit)
1097 oldEditValues = new DataKey (new OrderedDictionary ());
1098 key = new DataKey (new OrderedDictionary (), DataKeyNames);
1101 table.Rows.Add (CreateEmptyrRow ());
1104 rows = new DetailsViewRowCollection (list);
1106 if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
1107 bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
1108 InitializePager (bottomPagerRow, dataSource);
1109 table.Rows.Add (bottomPagerRow);
1112 if (FooterText.Length != 0 || footerTemplate != null) {
1113 footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal);
1114 DataControlFieldCell cell = new DataControlFieldCell (null);
1115 cell.ColumnSpan = 2;
1116 if (footerTemplate != null)
1117 footerTemplate.InstantiateIn (cell);
1119 cell.Text = FooterText;
1120 footerRow.Cells.Add (cell);
1121 table.Rows.Add (footerRow);
1127 return dataSource.DataSourceCount;
1131 protected override void EnsureDataBound ()
1133 throw new NotImplementedException ();
1136 DataControlRowState GetRowState (int index)
1138 DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
1139 if (CurrentMode == DetailsViewMode.Edit) rstate |= DataControlRowState.Edit;
1140 else if (CurrentMode == DetailsViewMode.Insert) rstate |= DataControlRowState.Insert;
1144 protected virtual void InitializePager (DetailsViewRow row, PagedDataSource dataSource)
1146 TableCell cell = new TableCell ();
1147 cell.ColumnSpan = 2;
1149 if (pagerTemplate != null)
1150 pagerTemplate.InstantiateIn (cell);
1152 cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
1154 row.Cells.Add (cell);
1157 DetailsViewRow CreateEmptyrRow ()
1159 DetailsViewRow row = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
1160 TableCell cell = new TableCell ();
1161 cell.ColumnSpan = 2;
1163 if (emptyDataTemplate != null)
1164 emptyDataTemplate.InstantiateIn (cell);
1166 cell.Text = EmptyDataText;
1168 row.Cells.Add (cell);
1172 protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
1174 DataControlFieldCell cell;
1176 if (field.ShowHeader) {
1177 cell = new DataControlFieldCell (field);
1178 row.Cells.Add (cell);
1179 field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
1182 cell = new DataControlFieldCell (field);
1183 if (!field.ShowHeader)
1184 cell.ColumnSpan = 2;
1185 row.Cells.Add (cell);
1186 field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);
1189 IOrderedDictionary CreateRowDataKey (object dataItem)
1191 if (cachedKeyProperties == null) {
1192 PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
1193 cachedKeyProperties = new PropertyDescriptor [DataKeyNames.Length];
1194 for (int n=0; n<DataKeyNames.Length; n++) {
1195 PropertyDescriptor p = props [DataKeyNames[n]];
1197 new InvalidOperationException ("Property '" + DataKeyNames[n] + "' not found in object of type " + dataItem.GetType());
1198 cachedKeyProperties [n] = p;
1202 OrderedDictionary dic = new OrderedDictionary ();
1203 foreach (PropertyDescriptor p in cachedKeyProperties)
1204 dic [p.Name] = p.GetValue (dataItem);
1208 IOrderedDictionary GetRowValues (bool includeReadOnlyFields, bool includePrimaryKey)
1210 OrderedDictionary dic = new OrderedDictionary ();
1211 ExtractRowValues (dic, includeReadOnlyFields, includePrimaryKey);
1215 protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, bool includeReadOnlyFields, bool includePrimaryKey)
1217 foreach (DetailsViewRow row in Rows) {
1218 if (row.Cells.Count < 1) continue;
1219 DataControlFieldCell c = row.Cells[row.Cells.Count-1] as DataControlFieldCell;
1221 c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
1223 if (!includePrimaryKey && DataKeyNames != null)
1224 foreach (string key in DataKeyNames)
1225 fieldValues.Remove (key);
1228 protected override HtmlTextWriterTag TagKey {
1230 if (EnablePagingCallbacks)
1231 return HtmlTextWriterTag.Div;
1233 return HtmlTextWriterTag.Table;
1237 public sealed override void DataBind ()
1239 DataSourceView view = GetData ();
1240 if (AllowPaging && view.CanPage) {
1241 SelectArguments.StartRowIndex = PageIndex;
1242 SelectArguments.MaximumRows = 1;
1243 if (view.CanRetrieveTotalRowCount)
1244 SelectArguments.RetrieveTotalRowCount = true;
1247 cachedKeyProperties = null;
1250 if (dataItem != null) {
1251 if (CurrentMode == DetailsViewMode.Edit)
1252 oldEditValues = new DataKey (GetRowValues (false, true));
1253 key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
1257 protected internal override void PerformDataBinding (IEnumerable data)
1259 base.PerformDataBinding (data);
1263 protected internal virtual void PrepareControlHierarchy ()
1265 throw new NotImplementedException ();
1268 protected internal override void OnInit (EventArgs e)
1270 Page.RegisterRequiresControlState (this);
1274 void OnFieldsChanged (object sender, EventArgs args)
1279 protected override void OnDataSourceViewChanged (object sender, EventArgs e)
1281 base.OnDataSourceViewChanged (sender, e);
1285 protected override bool OnBubbleEvent (object source, EventArgs e)
1287 DetailsViewCommandEventArgs args = e as DetailsViewCommandEventArgs;
1289 OnItemCommand (args);
1290 ProcessEvent (args.CommandName, args.CommandArgument as string);
1292 return base.OnBubbleEvent (source, e);
1295 // TODO: This is prolly obsolete
1296 protected virtual void RaisePostBackEvent (string eventArgument)
1298 int i = eventArgument.IndexOf ('$');
1300 ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
1302 ProcessEvent (eventArgument, null);
1305 void ProcessEvent (string eventName, string param)
1309 case DataControlCommands.PageCommandName:
1312 case DataControlCommands.FirstPageCommandArgument:
1315 case DataControlCommands.LastPageCommandArgument:
1316 newIndex = PageCount - 1;
1318 case DataControlCommands.NextPageCommandArgument:
1319 if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
1321 case DataControlCommands.PreviousPageCommandArgument:
1322 if (PageIndex > 0) newIndex = PageIndex - 1;
1325 newIndex = int.Parse (param) - 1;
1328 ShowPage (newIndex);
1331 case DataControlCommands.FirstPageCommandArgument:
1335 case DataControlCommands.LastPageCommandArgument:
1336 ShowPage (PageCount - 1);
1339 case DataControlCommands.NextPageCommandArgument:
1340 if (PageIndex < PageCount - 1)
1341 ShowPage (PageIndex + 1);
1344 case DataControlCommands.PreviousPageCommandArgument:
1346 ShowPage (PageIndex - 1);
1349 case DataControlCommands.EditCommandName:
1350 ChangeMode (DetailsViewMode.Edit);
1353 case DataControlCommands.NewCommandName:
1354 ChangeMode (DetailsViewMode.Insert);
1357 case DataControlCommands.UpdateCommandName:
1358 UpdateItem (param, true);
1361 case DataControlCommands.CancelCommandName:
1365 case DataControlCommands.DeleteCommandName:
1369 case DataControlCommands.InsertCommandName:
1375 void ShowPage (int newIndex)
1377 DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
1378 OnPageIndexChanging (args);
1381 PageIndex = args.NewPageIndex;
1382 OnPageIndexChanged (EventArgs.Empty);
1386 public void ChangeMode (DetailsViewMode newMode)
1388 DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
1389 OnModeChanging (args);
1391 currentMode = args.NewMode;
1392 OnModeChanged (EventArgs.Empty);
1399 DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
1400 OnModeChanging (args);
1406 public virtual void UpdateItem (bool causesValidation)
1408 UpdateItem (null, causesValidation);
1411 void UpdateItem (string param, bool causesValidation)
1413 if (causesValidation)
1416 if (currentMode != DetailsViewMode.Edit) throw new NotSupportedException ();
1418 currentEditOldValues = oldEditValues.Values;
1420 currentEditRowKeys = DataKey.Values;
1421 currentEditNewValues = GetRowValues (false, false);
1423 DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
1424 OnItemUpdating (args);
1426 DataSourceView view = GetData ();
1427 if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
1428 view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
1433 bool UpdateCallback (int recordsAffected, Exception exception)
1435 DetailsViewUpdatedEventArgs dargs = new DetailsViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
1436 OnItemUpdated (dargs);
1438 if (!dargs.KeepInEditMode)
1441 return dargs.ExceptionHandled;
1444 public virtual void InsertItem (bool causesValidation)
1446 InsertItem (null, causesValidation);
1449 void InsertItem (string param, bool causesValidation)
1451 if (causesValidation)
1454 if (currentMode != DetailsViewMode.Insert) throw new NotSupportedException ();
1456 currentEditNewValues = GetRowValues (false, true);
1457 DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
1458 OnItemInserting (args);
1460 DataSourceView view = GetData ();
1461 if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
1462 view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
1467 bool InsertCallback (int recordsAffected, Exception exception)
1469 DetailsViewInsertedEventArgs dargs = new DetailsViewInsertedEventArgs (recordsAffected, exception, currentEditNewValues);
1470 OnItemInserted (dargs);
1472 if (!dargs.KeepInInsertMode)
1475 return dargs.ExceptionHandled;
1478 public void DeleteItem ()
1480 currentEditRowKeys = DataKey.Values;
1481 currentEditNewValues = GetRowValues (true, true);
1483 DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
1484 OnItemDeleting (args);
1487 if (PageIndex == PageCount - 1)
1490 DataSourceView view = GetData ();
1492 view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
1494 DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
1495 OnItemDeleted (dargs);
1500 bool DeleteCallback (int recordsAffected, Exception exception)
1502 DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
1503 OnItemDeleted (dargs);
1504 return dargs.ExceptionHandled;
1509 ChangeMode (DefaultMode);
1510 oldEditValues = new DataKey (new OrderedDictionary ());
1511 currentEditRowKeys = null;
1512 currentEditOldValues = null;
1513 currentEditNewValues = null;
1517 protected internal override void LoadControlState (object ob)
1519 if (ob == null) return;
1520 object[] state = (object[]) ob;
1521 base.LoadControlState (state[0]);
1522 pageIndex = (int) state[1];
1523 pageCount = (int) state[2];
1524 currentMode = (DetailsViewMode) state[3];
1527 protected internal override object SaveControlState ()
1529 object bstate = base.SaveControlState ();
1530 return new object[] {
1531 bstate, pageIndex, pageCount, currentMode
1535 protected override void TrackViewState()
1537 base.TrackViewState();
1538 if (columns != null) ((IStateManager)columns).TrackViewState();
1539 if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
1540 if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
1541 if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
1542 if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
1543 if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
1544 if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
1545 if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
1546 if (insertRowStyle != null) ((IStateManager)insertRowStyle).TrackViewState();
1547 if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
1548 if (key != null) ((IStateManager)key).TrackViewState();
1549 if (autoFieldProperties != null) {
1550 foreach (IStateManager sm in autoFieldProperties)
1551 sm.TrackViewState ();
1555 protected override object SaveViewState()
1557 object[] states = new object [14];
1558 states[0] = base.SaveViewState();
1559 states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
1560 states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
1561 states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
1562 states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
1563 states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
1564 states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
1565 states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
1566 states[8] = (insertRowStyle == null ? null : ((IStateManager)insertRowStyle).SaveViewState());
1567 states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
1568 states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
1569 states[11] = (key == null ? null : ((IStateManager)key).SaveViewState());
1570 states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
1572 if (autoFieldProperties != null) {
1573 object[] data = new object [autoFieldProperties.Length];
1574 bool allNull = true;
1575 for (int n=0; n<data.Length; n++) {
1576 data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
1577 if (data [n] != null) allNull = false;
1579 if (!allNull) states [13] = data;
1582 for (int i = states.Length - 1; i >= 0; i--) {
1583 if (states [i] != null)
1590 protected override void LoadViewState (object savedState)
1592 if (savedState == null) {
1593 base.LoadViewState (null);
1597 object [] states = (object []) savedState;
1599 if (states[13] != null) {
1600 object[] data = (object[]) states [13];
1601 autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
1602 for (int n=0; n<data.Length; n++) {
1603 IStateManager p = new AutoGeneratedFieldProperties ();
1604 p.TrackViewState ();
1605 p.LoadViewState (data [n]);
1606 autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
1610 base.LoadViewState (states[0]);
1611 EnsureChildControls ();
1613 if (states[1] != null) ((IStateManager)Fields).LoadViewState (states[1]);
1614 if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
1615 if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
1616 if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
1617 if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
1618 if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
1619 if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
1620 if (states[8] != null) ((IStateManager)InsertRowStyle).LoadViewState (states[8]);
1621 if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
1622 if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
1623 if (states[11] != null) ((IStateManager)DataKey).LoadViewState (states[11]);
1624 if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
1627 string ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
1629 return RaiseCallbackEvent (eventArgs);
1632 protected virtual string RaiseCallbackEvent (string eventArgs)
1634 string[] clientData = eventArgs.Split ('|');
1635 pageIndex = int.Parse (clientData[0]);
1638 RaisePostBackEvent (clientData[2]);
1641 StringWriter sw = new StringWriter ();
1642 sw.Write (PageIndex.ToString());
1644 HtmlTextWriter writer = new HtmlTextWriter (sw);
1645 RenderGrid (writer);
1646 return sw.ToString ();
1650 protected virtual string GetCallbackScript (IButtonControl buttonControl, string argument)
1652 throw new NotImplementedException ();
1655 string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
1657 if (EnablePagingCallbacks)
1658 return "javascript:GridView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
1664 protected override void OnPagePreLoad (object sender, EventArgs e)
1666 throw new NotImplementedException ();
1669 protected internal override void OnPreRender (EventArgs e)
1671 base.OnPreRender (e);
1673 if (EnablePagingCallbacks)
1675 if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(GridView), "GridView.js")) {
1676 string url = Page.ClientScript.GetWebResourceUrl (typeof(GridView), "GridView.js");
1677 Page.ClientScript.RegisterClientScriptInclude (typeof(GridView), "GridView.js", url);
1680 string cgrid = ClientID + "_data";
1681 string script = string.Format ("var {0} = new Object ();\n", cgrid);
1682 script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
1683 script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
1684 Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
1686 // Make sure the basic script infrastructure is rendered
1687 Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
1688 Page.ClientScript.GetPostBackClientHyperlink (this, "");
1692 protected internal override void Render (HtmlTextWriter writer)
1694 if (EnablePagingCallbacks)
1695 base.RenderBeginTag (writer);
1697 RenderGrid (writer);
1699 if (EnablePagingCallbacks)
1700 base.RenderEndTag (writer);
1703 void RenderGrid (HtmlTextWriter writer)
1705 switch (GridLines) {
1706 case GridLines.Horizontal:
1707 writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
1708 writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
1710 case GridLines.Vertical:
1711 writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
1712 writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
1714 case GridLines.Both:
1715 writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
1716 writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
1719 writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
1723 writer.AddAttribute (HtmlTextWriterAttribute.Cellspacing, "0");
1724 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderCollapse, "collapse");
1725 table.RenderBeginTag (writer);
1727 foreach (DetailsViewRow row in table.Rows)
1729 switch (row.RowType) {
1730 case DataControlRowType.Header:
1731 if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
1733 case DataControlRowType.Footer:
1734 if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
1736 case DataControlRowType.Pager:
1737 if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
1739 case DataControlRowType.EmptyDataRow:
1740 if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
1743 if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
1747 if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
1748 alternatingRowStyle.AddAttributesToRender (writer, row);
1749 if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
1750 editRowStyle.AddAttributesToRender (writer, row);
1751 if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null)
1752 insertRowStyle.AddAttributesToRender (writer, row);
1754 if (row == commandRow && commandRowStyle != null)
1755 commandRowStyle.AddAttributesToRender (writer, row);
1757 row.RenderBeginTag (writer);
1759 for (int n=0; n<row.Cells.Count; n++) {
1760 DataControlFieldCell fcell = row.Cells[n] as DataControlFieldCell;
1761 if (fcell != null && fcell.ContainingField != null) {
1762 if (n == 0 && fcell.ContainingField.ShowHeader) {
1763 if (fieldHeaderStyle != null)
1764 fieldHeaderStyle.AddAttributesToRender (writer, fcell);
1765 fcell.ContainingField.HeaderStyle.AddAttributesToRender (writer, fcell);
1768 fcell.ContainingField.ItemStyle.AddAttributesToRender (writer, fcell);
1770 row.Cells[n].Render (writer);
1772 row.RenderEndTag (writer);
1774 table.RenderEndTag (writer);