2 // System.Web.UI.WebControls.DataList.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 using System.Collections;
14 using System.ComponentModel;
15 using System.ComponentModel.Design;
18 using System.Web.Util;
20 namespace System.Web.UI.WebControls
22 [Designer("System.Web.UI.Design.WebControls.DataListDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
23 [Editor ("System.Web.UI.Design.WebControls.DataListComponentEditor, " + Consts.AssemblySystem_Design, typeof (ComponentEditor))]
24 public class DataList: BaseDataList, INamingContainer, IRepeatInfoUser
26 public const string CancelCommandName = "Cancel";
27 public const string DeleteCommandName = "Delete";
28 public const string EditCommandName = "Edit";
29 public const string SelectCommandName = "Select";
30 public const string UpdateCommandName = "Update";
32 static readonly object CancelCommandEvent = new object ();
33 static readonly object DeleteCommandEvent = new object ();
34 static readonly object EditCommandEvent = new object ();
35 static readonly object ItemCommandEvent = new object ();
36 static readonly object ItemCreatedEvent = new object ();
37 static readonly object ItemDataBoundEvent = new object ();
38 static readonly object UpdateCommandEvent = new object ();
40 TableItemStyle alternatingItemStyle;
41 TableItemStyle editItemStyle;
42 TableItemStyle footerStyle;
43 TableItemStyle headerStyle;
44 TableItemStyle itemStyle;
45 TableItemStyle selectedItemStyle;
46 TableItemStyle separatorStyle;
48 ITemplate alternatingItemTemplate;
49 ITemplate editItemTemplate;
50 ITemplate footerTemplate;
51 ITemplate headerTemplate;
52 ITemplate itemTemplate;
53 ITemplate selectedItemTemplate;
54 ITemplate separatorTemplate;
57 DataListItemCollection items;
59 bool extractTemplateRows;
66 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
67 [NotifyParentProperty (true)]
68 [WebCategory ("Style")]
69 [PersistenceMode (PersistenceMode.InnerProperty)]
70 [WebSysDescription ("The style applied to alternating items.")]
71 public virtual TableItemStyle AlternatingItemStyle {
73 if (alternatingItemStyle == null) {
74 alternatingItemStyle = new TableItemStyle ();
75 if (IsTrackingViewState)
76 alternatingItemStyle.TrackViewState ();
79 return alternatingItemStyle;
85 [TemplateContainer (typeof (DataListItem))]
86 [PersistenceMode (PersistenceMode.InnerProperty)]
87 [WebSysDescription ("The template used for alternating items.")]
88 public virtual ITemplate AlternatingItemTemplate {
89 get { return alternatingItemTemplate; }
90 set { alternatingItemTemplate = value; }
94 [WebCategory ("Misc")]
95 [WebSysDescription ("The index of the item shown in edit mode.")]
96 public virtual int EditItemIndex {
98 object o = ViewState ["EditItemIndex"];
107 throw new ArgumentOutOfRangeException("value");
109 ViewState ["EditItemIndex"] = value;
113 [DefaultValue (null)]
114 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
115 [NotifyParentProperty (true)]
116 [WebCategory ("Style")]
117 [PersistenceMode (PersistenceMode.InnerProperty)]
118 [WebSysDescription ("The style applied to items in edit mode.")]
119 public virtual TableItemStyle EditItemStyle {
121 if (editItemStyle == null) {
122 editItemStyle = new TableItemStyle ();
123 if (IsTrackingViewState)
124 editItemStyle.TrackViewState ();
127 return editItemStyle;
132 [DefaultValue (null)]
133 [TemplateContainer (typeof (DataListItem))]
134 [PersistenceMode (PersistenceMode.InnerProperty)]
135 [WebSysDescription ("The template used for items in edit mode.")]
136 public virtual ITemplate EditItemTemplate {
137 get { return editItemTemplate; }
138 set { editItemTemplate = value; }
142 [DefaultValue (false), WebCategory ("Misc")]
143 [WebSysDescription ("Extract rows in the template.")]
144 public virtual bool ExtractTemplateRows {
146 object o = ViewState ["ExtractTemplateRows"];
153 set { ViewState ["ExtractTemplateRows"] = value; }
156 [DefaultValue (null)]
157 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
158 [NotifyParentProperty (true)]
159 [WebCategory ("Style")]
160 [PersistenceMode (PersistenceMode.InnerProperty)]
161 [WebSysDescription ("The style applied to the footer.")]
162 public virtual TableItemStyle FooterStyle {
164 if (footerStyle == null) {
165 footerStyle = new TableItemStyle ();
166 if (IsTrackingViewState)
167 footerStyle.TrackViewState ();
175 [DefaultValue (null)]
176 [TemplateContainer (typeof (DataListItem))]
177 [PersistenceMode (PersistenceMode.InnerProperty)]
178 [WebSysDescription ("The template used for the footer.")]
179 public virtual ITemplate FooterTemplate {
180 get { return footerTemplate; }
181 set { footerTemplate = value; }
184 [DefaultValue (typeof (GridLines), "None")]
185 public override GridLines GridLines {
186 get { return base.GridLines; }
187 set { base.GridLines = value; }
190 [DefaultValue (null)]
191 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
192 [NotifyParentProperty (true)]
193 [WebCategory ("Style")]
194 [PersistenceMode (PersistenceMode.InnerProperty)]
195 [WebSysDescription ("The style applied to the header.")]
196 public virtual TableItemStyle HeaderStyle {
198 if (headerStyle == null) {
199 headerStyle = new TableItemStyle ();
200 if (IsTrackingViewState)
201 headerStyle.TrackViewState ();
209 [DefaultValue (null)]
210 [TemplateContainer (typeof (DataListItem))]
211 [PersistenceMode (PersistenceMode.InnerProperty)]
212 [WebSysDescription ("The template used for the header.")]
213 public virtual ITemplate HeaderTemplate {
214 get { return headerTemplate; }
215 set { headerTemplate = value; }
219 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
220 [WebSysDescription ("A colletion containing all items.")]
221 public virtual DataListItemCollection Items {
224 if (itemsArray == null) {
225 EnsureChildControls ();
226 itemsArray = new ArrayList ();
228 items = new DataListItemCollection (itemsArray);
235 [DefaultValue (null)]
236 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
237 [NotifyParentProperty (true)]
238 [WebCategory ("Style")]
239 [PersistenceMode (PersistenceMode.InnerProperty)]
240 [WebSysDescription ("The style applied to items.")]
241 public virtual TableItemStyle ItemStyle {
243 if (itemStyle == null) {
244 itemStyle = new TableItemStyle ();
245 if (IsTrackingViewState)
246 itemStyle.TrackViewState ();
254 [DefaultValue (null)]
255 [TemplateContainer (typeof (DataListItem))]
256 [PersistenceMode (PersistenceMode.InnerProperty)]
257 [WebSysDescription ("The template used for items.")]
258 public virtual ITemplate ItemTemplate {
259 get { return itemTemplate; }
260 set { itemTemplate = value; }
264 [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
265 [WebSysDescription ("The number of columns that should be used.")]
266 public virtual int RepeatColumns {
268 object o = ViewState ["RepeatColumns"];
276 throw new ArgumentOutOfRangeException ("value", "RepeatColumns value has to be 0 for 'not set' or > 0.");
278 ViewState ["RepeatColumns"] = value;
282 [DefaultValue (typeof (RepeatDirection), "Vertical"), Bindable (true), WebCategory ("Layout")]
283 [WebSysDescription ("Which direction should be used when filling the columns.")]
284 public virtual RepeatDirection RepeatDirection {
286 object o = ViewState ["RepeatDirection"];
288 return (RepeatDirection) o;
290 return RepeatDirection.Vertical;
293 if (!Enum.IsDefined (typeof (RepeatDirection), value))
294 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
296 ViewState ["RepeatDirection"] = value;
300 [DefaultValue (typeof (RepeatLayout), "Table"), Bindable (true), WebCategory ("Layout")]
301 [WebSysDescription ("The type of layout - mechanism that is used.")]
302 public virtual RepeatLayout RepeatLayout {
304 object o = ViewState ["RepeatLayout"];
306 return (RepeatLayout) o;
308 return RepeatLayout.Table;
311 if (!Enum.IsDefined (typeof (RepeatLayout), value))
312 throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
314 ViewState ["RepeatLayout"] = value;
318 [DefaultValue (-1), Bindable (true)]
319 [WebSysDescription ("The currently selected item index number.")]
320 public virtual int SelectedIndex {
322 object o = ViewState ["SelectedIndex"];
329 //FIXME: Looks like a bug in Microsoft's specs.
330 // Exception is missing in document. I haven't tested the case
331 // But I think exception should follow
333 throw new ArgumentOutOfRangeException("value");
335 int prevSel = SelectedIndex;
336 ViewState ["SelectedIndex"] = value;
337 DataListItem prevSelItem;
340 if (itemsArray != null) {
341 if (prevSel >= 0 && prevSel < itemsArray.Count) {
342 prevSelItem = (DataListItem) itemsArray [prevSel];
343 if (prevSelItem.ItemType != ListItemType.EditItem) {
344 liType = ((prevSel % 2) == 0 ? ListItemType.AlternatingItem :
347 prevSelItem.SetItemType (liType);
351 if (value >= 0 && value < itemsArray.Count) {
352 prevSelItem = (DataListItem) itemsArray [value];
353 if (prevSelItem.ItemType != ListItemType.EditItem) {
354 prevSelItem.SetItemType (ListItemType.SelectedItem);
362 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
363 [WebSysDescription ("The currently selected item.")]
364 public virtual DataListItem SelectedItem {
366 if (SelectedIndex == -1)
369 return Items [SelectedIndex];
373 [DefaultValue (null)]
374 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
375 [NotifyParentProperty (true)]
376 [WebCategory ("Style")]
377 [PersistenceMode (PersistenceMode.InnerProperty)]
378 [WebSysDescription ("The style used for the currently selected item.")]
379 public virtual TableItemStyle SelectedItemStyle {
381 if (selectedItemStyle == null) {
382 selectedItemStyle = new TableItemStyle ();
383 if (IsTrackingViewState)
384 selectedItemStyle.TrackViewState ();
387 return selectedItemStyle;
392 [DefaultValue (null)]
393 [TemplateContainer (typeof (DataListItem))]
394 [PersistenceMode (PersistenceMode.InnerProperty)]
395 [WebSysDescription ("The template used for currently selected items.")]
396 public virtual ITemplate SelectedItemTemplate {
397 get { return selectedItemTemplate; }
398 set { selectedItemTemplate = value; }
401 [DefaultValue (null)]
402 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
403 [NotifyParentProperty (true)]
404 [WebCategory ("Style")]
405 [PersistenceMode (PersistenceMode.InnerProperty)]
406 [WebSysDescription ("The style applied to separators.")]
407 public virtual TableItemStyle SeparatorStyle {
409 if (separatorStyle == null) {
410 separatorStyle = new TableItemStyle ();
411 if (IsTrackingViewState)
412 separatorStyle.TrackViewState ();
415 return separatorStyle;
420 [DefaultValue (null)]
421 [TemplateContainer (typeof (DataListItem))]
422 [PersistenceMode (PersistenceMode.InnerProperty)]
423 [WebSysDescription ("The template used for separators.")]
424 public virtual ITemplate SeparatorTemplate {
425 get { return separatorTemplate; }
426 set { separatorTemplate = value; }
429 [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
430 [WebSysDescription ("Display the header for the DataList.")]
431 public virtual bool ShowHeader {
433 object o = ViewState ["ShowHeader"];
439 set { ViewState ["ShowHeader"] = value; }
442 [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
443 [WebSysDescription ("Display the footer for the DataList.")]
444 public virtual bool ShowFooter {
446 object o = ViewState ["ShowFooter"];
454 ViewState["ShowFooter"] = value;
458 [WebCategory ("Action")]
459 [WebSysDescription ("Raised when a cancel command is generated.")]
460 public event DataListCommandEventHandler CancelCommand {
461 add { Events.AddHandler (CancelCommandEvent, value); }
462 remove { Events.RemoveHandler (CancelCommandEvent, value); }
465 [WebCategory ("Action")]
466 [WebSysDescription ("Raised when a delete command is generated.")]
467 public event DataListCommandEventHandler DeleteCommand {
468 add { Events.AddHandler (DeleteCommandEvent, value); }
469 remove { Events.RemoveHandler (DeleteCommandEvent, value); }
472 [WebCategory ("Action")]
473 [WebSysDescription ("Raised when an edit command is generated.")]
474 public event DataListCommandEventHandler EditCommand {
475 add { Events.AddHandler (EditCommandEvent, value); }
476 remove { Events.RemoveHandler (EditCommandEvent, value); }
479 [WebCategory ("Action")]
480 [WebSysDescription ("Raised when an item command is generated.")]
481 public event DataListCommandEventHandler ItemCommand {
482 add { Events.AddHandler (ItemCommandEvent, value); }
483 remove { Events.RemoveHandler (ItemCommandEvent, value); }
486 [WebCategory ("Behavior")]
487 [WebSysDescription ("Raised when a new item is created.")]
488 public event DataListItemEventHandler ItemCreated {
489 add { Events.AddHandler (ItemCreatedEvent, value); }
490 remove { Events.RemoveHandler (ItemCreatedEvent, value); }
493 [WebCategory ("Behavior")]
494 [WebSysDescription ("Raised when a item gets data-bound.")]
495 public event DataListItemEventHandler ItemDataBound {
496 add { Events.AddHandler (ItemDataBoundEvent, value); }
497 remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
500 [WebCategory ("Action")]
501 [WebSysDescription ("Raised when an update command is generated.")]
502 public event DataListCommandEventHandler UpdateCommand {
503 add { Events.AddHandler (UpdateCommandEvent, value); }
504 remove { Events.RemoveHandler (UpdateCommandEvent, value); }
507 protected override Style CreateControlStyle ()
509 TableStyle retVal = new TableStyle (ViewState);
510 retVal.CellSpacing = 0;
514 protected override void LoadViewState (object savedState)
516 if (savedState == null)
519 object [] states = (object []) savedState;
521 if (states [0] != null)
522 base.LoadViewState (states [0]);
523 if (states [1] != null)
524 alternatingItemStyle.LoadViewState (states [1]);
525 if (states [2] != null)
526 editItemStyle.LoadViewState (states [2]);
527 if (states [3] != null)
528 footerStyle.LoadViewState (states [3]);
529 if (states [4] != null)
530 headerStyle.LoadViewState (states [4]);
531 if (states [5] != null)
532 itemStyle.LoadViewState (states [5]);
533 if (states [6] != null)
534 selectedItemStyle.LoadViewState (states [6]);
535 if (states [7] != null)
536 separatorStyle.LoadViewState (states [7]);
539 protected override object SaveViewState()
541 object [] states = new object [8];
542 states [0] = base.SaveViewState ();
543 states [1] = (alternatingItemStyle == null ? null : alternatingItemStyle.SaveViewState ());
544 states [2] = (editItemStyle == null ? null : editItemStyle.SaveViewState ());
545 states [3] = (footerStyle == null ? null : footerStyle.SaveViewState ());
546 states [4] = (headerStyle == null ? null : headerStyle.SaveViewState ());
547 states [5] = (itemStyle == null ? null : itemStyle.SaveViewState ());
548 states [6] = (selectedItemStyle == null ? null : selectedItemStyle.SaveViewState ());
549 states [7] = (separatorStyle == null ? null : separatorStyle.SaveViewState ());
553 protected override void TrackViewState ()
555 base.TrackViewState ();
556 if (alternatingItemStyle != null)
557 alternatingItemStyle.TrackViewState ();
558 if (editItemStyle != null)
559 editItemStyle.TrackViewState ();
560 if (footerStyle != null)
561 footerStyle.TrackViewState ();
562 if (headerStyle != null)
563 headerStyle.TrackViewState ();
564 if (itemStyle != null)
565 itemStyle.TrackViewState ();
566 if (selectedItemStyle != null)
567 selectedItemStyle.TrackViewState ();
568 if (separatorStyle != null)
569 separatorStyle.TrackViewState ();
572 protected override bool OnBubbleEvent (object source, EventArgs e)
574 if (!(e is DataListCommandEventArgs))
577 DataListCommandEventArgs args = (DataListCommandEventArgs) e;
578 OnItemCommand (args);
579 string cmdName = args.CommandName.ToLower ();
581 if (cmdName == "cancel") {
582 OnCancelCommand (args);
583 } else if (cmdName == "delete") {
584 OnDeleteCommand (args);
585 } else if (cmdName == "edit") {
586 OnEditCommand (args);
587 } else if (cmdName == "select") {
588 SelectedIndex = args.Item.ItemIndex;
589 OnSelectedIndexChanged (EventArgs.Empty);
590 } else if (cmdName == "update") {
591 OnUpdateCommand (args);
597 void InvokeCommandEvent (DataListCommandEventArgs args, object key)
599 DataListCommandEventHandler dlceh = (DataListCommandEventHandler) Events [key];
604 void InvokeItemEvent (DataListItemEventArgs args, object key)
606 DataListItemEventHandler dlieh = (DataListItemEventHandler) Events [key];
611 protected virtual void OnCancelCommand (DataListCommandEventArgs e)
613 InvokeCommandEvent (e, CancelCommandEvent);
616 protected virtual void OnDeleteCommand (DataListCommandEventArgs e)
618 InvokeCommandEvent (e, DeleteCommandEvent);
621 protected virtual void OnEditCommand (DataListCommandEventArgs e)
623 InvokeCommandEvent (e, EditCommandEvent);
626 protected virtual void OnItemCommand (DataListCommandEventArgs e)
628 InvokeCommandEvent (e, ItemCommandEvent);
631 protected virtual void OnItemCreated (DataListItemEventArgs e)
633 InvokeItemEvent (e, ItemCreatedEvent);
636 protected virtual void OnItemDataBound (DataListItemEventArgs e)
638 InvokeItemEvent (e, ItemDataBoundEvent);
641 protected virtual void OnUpdateCommand (DataListCommandEventArgs e)
643 InvokeCommandEvent (e, UpdateCommandEvent);
646 protected override void RenderContents (HtmlTextWriter writer)
648 if (Controls.Count == 0)
651 RepeatInfo repeater = new RepeatInfo ();
652 Table templateTable = null;
653 if (extractTemplateRows) {
654 repeater.RepeatDirection = RepeatDirection.Vertical;
655 repeater.RepeatLayout = RepeatLayout.Flow;
656 repeater.RepeatColumns = 1;
657 repeater.OuterTableImplied = true;
659 templateTable = new Table ();
660 templateTable.ID = ClientID;
661 templateTable.CopyBaseAttributes (this);
662 templateTable.ApplyStyle (ControlStyle);
663 templateTable.RenderBeginTag (writer);
665 repeater.RepeatDirection = RepeatDirection;
666 repeater.RepeatLayout = RepeatLayout;
667 repeater.RepeatColumns = RepeatColumns;
670 repeater.RenderRepeater (writer, this, ControlStyle, this);
671 if (templateTable != null) {
672 templateTable.RenderEndTag (writer);
676 private DataListItem GetItem (ListItemType itemType, int repeatIndex)
678 DataListItem retVal = null;
680 case ListItemType.Header:
681 retVal = (DataListItem) Controls [0];
683 case ListItemType.Footer:
684 retVal = (DataListItem) Controls [Controls.Count - 1];
686 case ListItemType.Item:
687 goto case ListItemType.EditItem;
688 case ListItemType.AlternatingItem:
689 goto case ListItemType.EditItem;
690 case ListItemType.SelectedItem:
691 goto case ListItemType.EditItem;
692 case ListItemType.EditItem:
693 retVal = (DataListItem) itemsArray [repeatIndex];
695 case ListItemType.Separator:
696 int index = 2 * repeatIndex + 1;
697 if (headerTemplate != null)
699 retVal = (DataListItem) Controls [index];
708 protected override void CreateControlHierarchy (bool useDataSource)
710 IEnumerable source = null;
711 ArrayList dkeys = DataKeysArray;
713 if (itemsArray != null) {
716 itemsArray = new ArrayList ();
719 extractTemplateRows = ExtractTemplateRows;
720 if (!useDataSource) {
721 int count = (int) ViewState ["_!ItemCount"];
723 source = new DataSourceInternal (count);
724 itemsArray.Capacity = count;
728 source = GetResolvedDataSource ();
729 if (source is ICollection) {
730 dkeys.Capacity = ((ICollection) source).Count;
731 itemsArray.Capacity = ((ICollection) source).Count;
736 if (source != null) {
738 int editIndex = EditItemIndex;
739 int selIndex = SelectedIndex;
740 string dataKey = DataKeyField;
742 if (headerTemplate != null)
743 CreateItem (-1, ListItemType.Header, useDataSource, null);
745 foreach (object current in source) {
748 dkeys.Add (DataBinder.GetPropertyValue (current, dataKey));
750 dkeys.Add (dkeys.Count);
754 ListItemType type = ListItemType.Item;
755 if (index == editIndex) {
756 type = ListItemType.EditItem;
757 } else if (index == selIndex) {
758 type = ListItemType.SelectedItem;
759 } else if ((index % 2) != 0) {
760 type = ListItemType.AlternatingItem;
763 itemsArray.Add (CreateItem (index, type, useDataSource, current));
764 if (separatorTemplate != null)
765 CreateItem (index, ListItemType.Separator, useDataSource, null);
770 if (footerTemplate != null)
771 CreateItem (-1, ListItemType.Footer, useDataSource, null);
775 ViewState ["_!ItemCount"] = (source != null ? itemCount : -1);
781 protected virtual DataListItem CreateItem (int itemIndex, ListItemType itemType)
783 return new DataListItem (itemIndex, itemType);
786 private DataListItem CreateItem (int itemIndex, ListItemType itemType, bool dataBind, object dataItem)
788 DataListItem retVal = CreateItem (itemIndex, itemType);
789 DataListItemEventArgs e = new DataListItemEventArgs (retVal);
790 InitializeItem (retVal);
792 retVal.DataItem = dataItem;
795 Controls.Add (retVal);
800 retVal.DataItem = null;
809 protected override void PrepareControlHierarchy ()
811 if (Controls.Count == 0)
814 Style defaultStyle = null;
815 Style rowStyle = null;
817 if (alternatingItemStyle != null) {
818 defaultStyle = new TableItemStyle ();
819 defaultStyle.CopyFrom (itemStyle);
820 defaultStyle.CopyFrom (alternatingItemStyle);
822 defaultStyle = itemStyle;
825 foreach (DataListItem current in Controls) {
827 switch (current.ItemType) {
828 case ListItemType.Header:
829 if (headerStyle != null)
830 rowStyle = headerStyle;
832 case ListItemType.Footer:
833 if (footerStyle != null)
834 rowStyle = footerStyle;
836 case ListItemType.Separator:
837 rowStyle = separatorStyle;
839 case ListItemType.Item:
840 rowStyle = itemStyle;
842 case ListItemType.AlternatingItem:
843 rowStyle = defaultStyle;
845 case ListItemType.SelectedItem:
846 rowStyle = new TableItemStyle ();
847 if ((current.ItemIndex % 2) == 0) {
848 rowStyle.CopyFrom (itemStyle);
850 rowStyle.CopyFrom (defaultStyle);
852 rowStyle.CopyFrom (selectedItemStyle);
854 case ListItemType.EditItem:
855 rowStyle = new TableItemStyle ();
856 if ((current.ItemIndex % 2) == 0) {
857 rowStyle.CopyFrom (itemStyle);
859 rowStyle.CopyFrom (defaultStyle);
862 if (current.ItemIndex == SelectedIndex)
863 rowStyle.CopyFrom (selectedItemStyle);
865 rowStyle.CopyFrom (editItemStyle);
869 if (rowStyle == null)
872 if (!extractTemplateRows) {
873 current.MergeStyle (rowStyle);
877 foreach (Control currentCtrl in current.Controls) {
878 if (!(currentCtrl is Table))
881 foreach (TableRow cRow in ((Table) currentCtrl).Rows)
882 cRow.MergeStyle (rowStyle);
890 protected virtual void InitializeItem (DataListItem item)
892 ListItemType type = item.ItemType;
893 ITemplate template = itemTemplate;
896 case ListItemType.Header:
897 template = headerTemplate;
899 case ListItemType.Footer:
900 template = footerTemplate;
902 case ListItemType.AlternatingItem:
903 if (alternatingItemTemplate != null)
904 template = alternatingItemTemplate;
906 case ListItemType.SelectedItem:
907 if (selectedItemTemplate != null) {
908 template = selectedItemTemplate;
912 if ((item.ItemIndex % 2) != 0)
913 goto case ListItemType.AlternatingItem;
915 case ListItemType.EditItem:
916 if (editItemTemplate != null) {
917 template = editItemTemplate;
921 if (item.ItemIndex == SelectedIndex)
922 goto case ListItemType.SelectedItem;
924 if ((item.ItemIndex % 2) != 0)
925 goto case ListItemType.AlternatingItem;
927 case ListItemType.Separator:
928 template = separatorTemplate;
932 if (template != null)
933 template.InstantiateIn (item);
936 bool IRepeatInfoUser.HasFooter {
937 get { return (ShowFooter && footerTemplate != null); }
940 bool IRepeatInfoUser.HasHeader {
941 get { return (ShowHeader && headerTemplate != null); }
944 bool IRepeatInfoUser.HasSeparators {
945 get { return (separatorTemplate != null); }
948 int IRepeatInfoUser.RepeatedItemCount {
950 if (itemsArray != null)
951 return itemsArray.Count;
957 void IRepeatInfoUser.RenderItem (ListItemType itemType,
959 RepeatInfo repeatInfo,
960 HtmlTextWriter writer)
962 DataListItem item = GetItem (itemType, repeatIndex);
964 item.RenderItem (writer,
966 (repeatInfo.RepeatLayout == RepeatLayout.Table));
969 Style IRepeatInfoUser.GetItemStyle (ListItemType itemType, int repeatIndex)
971 DataListItem item = GetItem (itemType, repeatIndex);
972 if (item == null || !item.ControlStyleCreated)
975 return item.ControlStyle;