| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- //
- // System.Web.UI.WebControls.DataList.cs
- //
- // Authors:
- // Gaurav Vaish ([email protected])
- // Andreas Nahr ([email protected])
- //
- // (C) Gaurav Vaish (2002)
- // (C) 2003 Andreas Nahr
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Web;
- using System.Web.UI;
- using System.Web.Util;
- namespace System.Web.UI.WebControls
- {
- [Designer("System.Web.UI.Design.WebControls.DataListDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
- [Editor ("System.Web.UI.Design.WebControls.DataListComponentEditor, " + Consts.AssemblySystem_Design, typeof (ComponentEditor))]
- public class DataList: BaseDataList, INamingContainer, IRepeatInfoUser
- {
- public const string CancelCommandName = "Cancel";
- public const string DeleteCommandName = "Delete";
- public const string EditCommandName = "Edit";
- public const string SelectCommandName = "Select";
- public const string UpdateCommandName = "Update";
- static readonly object CancelCommandEvent = new object ();
- static readonly object DeleteCommandEvent = new object ();
- static readonly object EditCommandEvent = new object ();
- static readonly object ItemCommandEvent = new object ();
- static readonly object ItemCreatedEvent = new object ();
- static readonly object ItemDataBoundEvent = new object ();
- static readonly object UpdateCommandEvent = new object ();
- TableItemStyle alternatingItemStyle;
- TableItemStyle editItemStyle;
- TableItemStyle footerStyle;
- TableItemStyle headerStyle;
- TableItemStyle itemStyle;
- TableItemStyle selectedItemStyle;
- TableItemStyle separatorStyle;
- ITemplate alternatingItemTemplate;
- ITemplate editItemTemplate;
- ITemplate footerTemplate;
- ITemplate headerTemplate;
- ITemplate itemTemplate;
- ITemplate selectedItemTemplate;
- ITemplate separatorTemplate;
- ArrayList itemsArray;
- DataListItemCollection items;
- bool extractTemplateRows;
- public DataList ()
- {
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to alternating items.")]
- public virtual TableItemStyle AlternatingItemStyle {
- get {
- if (alternatingItemStyle == null) {
- alternatingItemStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- alternatingItemStyle.TrackViewState ();
- }
- return alternatingItemStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for alternating items.")]
- public virtual ITemplate AlternatingItemTemplate {
- get { return alternatingItemTemplate; }
- set { alternatingItemTemplate = value; }
- }
- [DefaultValue (-1)]
- [WebCategory ("Misc")]
- [WebSysDescription ("The index of the item shown in edit mode.")]
- public virtual int EditItemIndex {
- get {
- object o = ViewState ["EditItemIndex"];
- if (o != null)
- return (int) o;
- return -1;
- }
- set {
- if (value < -1)
- throw new ArgumentOutOfRangeException("value");
-
- ViewState ["EditItemIndex"] = value;
- }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to items in edit mode.")]
- public virtual TableItemStyle EditItemStyle {
- get {
- if (editItemStyle == null) {
- editItemStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- editItemStyle.TrackViewState ();
- }
- return editItemStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for items in edit mode.")]
- public virtual ITemplate EditItemTemplate {
- get { return editItemTemplate; }
- set { editItemTemplate = value; }
- }
- [DefaultValue (false), WebCategory ("Misc")]
- [WebSysDescription ("Extract rows in the template.")]
- public virtual bool ExtractTemplateRows {
- get {
- object o = ViewState ["ExtractTemplateRows"];
- if (o != null)
- return (bool) o;
- return false;
- }
- set { ViewState ["ExtractTemplateRows"] = value; }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to the footer.")]
- public virtual TableItemStyle FooterStyle {
- get {
- if (footerStyle == null) {
- footerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- footerStyle.TrackViewState ();
- }
- return footerStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for the footer.")]
- public virtual ITemplate FooterTemplate {
- get { return footerTemplate; }
- set { footerTemplate = value; }
- }
- [DefaultValue (typeof (GridLines), "None")]
- public override GridLines GridLines {
- get { return base.GridLines; }
- set { base.GridLines = value; }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to the header.")]
- public virtual TableItemStyle HeaderStyle {
- get {
- if (headerStyle == null) {
- headerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- headerStyle.TrackViewState ();
- }
- return headerStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for the header.")]
- public virtual ITemplate HeaderTemplate {
- get { return headerTemplate; }
- set { headerTemplate = value; }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [WebSysDescription ("A colletion containing all items.")]
- public virtual DataListItemCollection Items {
- get {
- if (items == null) {
- if (itemsArray == null) {
- EnsureChildControls ();
- itemsArray = new ArrayList ();
- }
- items = new DataListItemCollection (itemsArray);
- }
- return items;
- }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to items.")]
- public virtual TableItemStyle ItemStyle {
- get {
- if (itemStyle == null) {
- itemStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- itemStyle.TrackViewState ();
- }
- return itemStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for items.")]
- public virtual ITemplate ItemTemplate {
- get { return itemTemplate; }
- set { itemTemplate = value; }
- }
- [DefaultValue (0), Bindable (true), WebCategory ("Layout")]
- [WebSysDescription ("The number of columns that should be used.")]
- public virtual int RepeatColumns {
- get {
- object o = ViewState ["RepeatColumns"];
- if (o != null)
- return (int) o;
- return 0;
- }
- set {
- if (value < 0)
- throw new ArgumentOutOfRangeException ("value", "RepeatColumns value has to be 0 for 'not set' or > 0.");
- ViewState ["RepeatColumns"] = value;
- }
- }
- [DefaultValue (typeof (RepeatDirection), "Vertical"), Bindable (true), WebCategory ("Layout")]
- [WebSysDescription ("Which direction should be used when filling the columns.")]
- public virtual RepeatDirection RepeatDirection {
- get {
- object o = ViewState ["RepeatDirection"];
- if (o != null)
- return (RepeatDirection) o;
- return RepeatDirection.Vertical;
- }
- set {
- if (!Enum.IsDefined (typeof (RepeatDirection), value))
- throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
- ViewState ["RepeatDirection"] = value;
- }
- }
- [DefaultValue (typeof (RepeatLayout), "Table"), Bindable (true), WebCategory ("Layout")]
- [WebSysDescription ("The type of layout - mechanism that is used.")]
- public virtual RepeatLayout RepeatLayout {
- get {
- object o = ViewState ["RepeatLayout"];
- if (o != null)
- return (RepeatLayout) o;
- return RepeatLayout.Table;
- }
- set {
- if (!Enum.IsDefined (typeof (RepeatLayout), value))
- throw new ArgumentOutOfRangeException ("value", "Only valid enumeration members are allowed");
- ViewState ["RepeatLayout"] = value;
- }
- }
- [DefaultValue (-1), Bindable (true)]
- [WebSysDescription ("The currently selected item index number.")]
- public virtual int SelectedIndex {
- get {
- object o = ViewState ["SelectedIndex"];
- if (o != null)
- return (int) o;
- return -1;
- }
- set {
- //FIXME: Looks like a bug in Microsoft's specs.
- // Exception is missing in document. I haven't tested the case
- // But I think exception should follow
- if (value < -1)
- throw new ArgumentOutOfRangeException("value");
- int prevSel = SelectedIndex;
- ViewState ["SelectedIndex"] = value;
- DataListItem prevSelItem;
- ListItemType liType;
- if (itemsArray != null) {
- if (prevSel >= 0 && prevSel < itemsArray.Count) {
- prevSelItem = (DataListItem) itemsArray [prevSel];
- if (prevSelItem.ItemType != ListItemType.EditItem) {
- liType = ((prevSel % 2) == 0 ? ListItemType.AlternatingItem :
- ListItemType.Item);
- prevSelItem.SetItemType (liType);
- }
- }
- if (value >= 0 && value < itemsArray.Count) {
- prevSelItem = (DataListItem) itemsArray [value];
- if (prevSelItem.ItemType != ListItemType.EditItem) {
- prevSelItem.SetItemType (ListItemType.SelectedItem);
- }
- }
- }
- }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [WebSysDescription ("The currently selected item.")]
- public virtual DataListItem SelectedItem {
- get {
- if (SelectedIndex == -1)
- return null;
- return Items [SelectedIndex];
- }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style used for the currently selected item.")]
- public virtual TableItemStyle SelectedItemStyle {
- get {
- if (selectedItemStyle == null) {
- selectedItemStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- selectedItemStyle.TrackViewState ();
- }
- return selectedItemStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for currently selected items.")]
- public virtual ITemplate SelectedItemTemplate {
- get { return selectedItemTemplate; }
- set { selectedItemTemplate = value; }
- }
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- [NotifyParentProperty (true)]
- [WebCategory ("Style")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The style applied to separators.")]
- public virtual TableItemStyle SeparatorStyle {
- get {
- if (separatorStyle == null) {
- separatorStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- separatorStyle.TrackViewState ();
- }
- return separatorStyle;
- }
- }
- [Browsable (false)]
- [DefaultValue (null)]
- [TemplateContainer (typeof (DataListItem))]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [WebSysDescription ("The template used for separators.")]
- public virtual ITemplate SeparatorTemplate {
- get { return separatorTemplate; }
- set { separatorTemplate = value; }
- }
- [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
- [WebSysDescription ("Display the header for the DataList.")]
- public virtual bool ShowHeader {
- get {
- object o = ViewState ["ShowHeader"];
- if (o != null)
- return (bool) o;
- return true;
- }
- set { ViewState ["ShowHeader"] = value; }
- }
- [DefaultValue (true), Bindable (true), WebCategory ("Appearance")]
- [WebSysDescription ("Display the footer for the DataList.")]
- public virtual bool ShowFooter {
- get {
- object o = ViewState ["ShowFooter"];
- if (o != null)
- return (bool) o;
- return true;
- }
- set
- {
- ViewState["ShowFooter"] = value;
- }
- }
- [WebCategory ("Action")]
- [WebSysDescription ("Raised when a cancel command is generated.")]
- public event DataListCommandEventHandler CancelCommand {
- add { Events.AddHandler (CancelCommandEvent, value); }
- remove { Events.RemoveHandler (CancelCommandEvent, value); }
- }
- [WebCategory ("Action")]
- [WebSysDescription ("Raised when a delete command is generated.")]
- public event DataListCommandEventHandler DeleteCommand {
- add { Events.AddHandler (DeleteCommandEvent, value); }
- remove { Events.RemoveHandler (DeleteCommandEvent, value); }
- }
- [WebCategory ("Action")]
- [WebSysDescription ("Raised when an edit command is generated.")]
- public event DataListCommandEventHandler EditCommand {
- add { Events.AddHandler (EditCommandEvent, value); }
- remove { Events.RemoveHandler (EditCommandEvent, value); }
- }
- [WebCategory ("Action")]
- [WebSysDescription ("Raised when an item command is generated.")]
- public event DataListCommandEventHandler ItemCommand {
- add { Events.AddHandler (ItemCommandEvent, value); }
- remove { Events.RemoveHandler (ItemCommandEvent, value); }
- }
- [WebCategory ("Behavior")]
- [WebSysDescription ("Raised when a new item is created.")]
- public event DataListItemEventHandler ItemCreated {
- add { Events.AddHandler (ItemCreatedEvent, value); }
- remove { Events.RemoveHandler (ItemCreatedEvent, value); }
- }
- [WebCategory ("Behavior")]
- [WebSysDescription ("Raised when a item gets data-bound.")]
- public event DataListItemEventHandler ItemDataBound {
- add { Events.AddHandler (ItemDataBoundEvent, value); }
- remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
- }
- [WebCategory ("Action")]
- [WebSysDescription ("Raised when an update command is generated.")]
- public event DataListCommandEventHandler UpdateCommand {
- add { Events.AddHandler (UpdateCommandEvent, value); }
- remove { Events.RemoveHandler (UpdateCommandEvent, value); }
- }
- protected override Style CreateControlStyle ()
- {
- TableStyle retVal = new TableStyle (ViewState);
- retVal.CellSpacing = 0;
- return retVal;
- }
- protected override void LoadViewState (object savedState)
- {
- if (savedState == null)
- return;
- object [] states = (object []) savedState;
- if (states [0] != null)
- base.LoadViewState (states [0]);
- if (states [1] != null)
- alternatingItemStyle.LoadViewState (states [1]);
- if (states [2] != null)
- editItemStyle.LoadViewState (states [2]);
- if (states [3] != null)
- footerStyle.LoadViewState (states [3]);
- if (states [4] != null)
- headerStyle.LoadViewState (states [4]);
- if (states [5] != null)
- itemStyle.LoadViewState (states [5]);
- if (states [6] != null)
- selectedItemStyle.LoadViewState (states [6]);
- if (states [7] != null)
- separatorStyle.LoadViewState (states [7]);
- }
- protected override object SaveViewState()
- {
- object [] states = new object [8];
- states [0] = base.SaveViewState ();
- states [1] = (alternatingItemStyle == null ? null : alternatingItemStyle.SaveViewState ());
- states [2] = (editItemStyle == null ? null : editItemStyle.SaveViewState ());
- states [3] = (footerStyle == null ? null : footerStyle.SaveViewState ());
- states [4] = (headerStyle == null ? null : headerStyle.SaveViewState ());
- states [5] = (itemStyle == null ? null : itemStyle.SaveViewState ());
- states [6] = (selectedItemStyle == null ? null : selectedItemStyle.SaveViewState ());
- states [7] = (separatorStyle == null ? null : separatorStyle.SaveViewState ());
- return states;
- }
- protected override void TrackViewState ()
- {
- base.TrackViewState ();
- if (alternatingItemStyle != null)
- alternatingItemStyle.TrackViewState ();
- if (editItemStyle != null)
- editItemStyle.TrackViewState ();
- if (footerStyle != null)
- footerStyle.TrackViewState ();
- if (headerStyle != null)
- headerStyle.TrackViewState ();
- if (itemStyle != null)
- itemStyle.TrackViewState ();
- if (selectedItemStyle != null)
- selectedItemStyle.TrackViewState ();
- if (separatorStyle != null)
- separatorStyle.TrackViewState ();
- }
- protected override bool OnBubbleEvent (object source, EventArgs e)
- {
- if (!(e is DataListCommandEventArgs))
- return false;
- DataListCommandEventArgs args = (DataListCommandEventArgs) e;
- OnItemCommand (args);
- string cmdName = args.CommandName.ToLower ();
- if (cmdName == "cancel") {
- OnCancelCommand (args);
- } else if (cmdName == "delete") {
- OnDeleteCommand (args);
- } else if (cmdName == "edit") {
- OnEditCommand (args);
- } else if (cmdName == "select") {
- SelectedIndex = args.Item.ItemIndex;
- OnSelectedIndexChanged (EventArgs.Empty);
- } else if (cmdName == "update") {
- OnUpdateCommand (args);
- }
- return true;
- }
- void InvokeCommandEvent (DataListCommandEventArgs args, object key)
- {
- DataListCommandEventHandler dlceh = (DataListCommandEventHandler) Events [key];
- if (dlceh != null)
- dlceh (this, args);
- }
-
- void InvokeItemEvent (DataListItemEventArgs args, object key)
- {
- DataListItemEventHandler dlieh = (DataListItemEventHandler) Events [key];
- if (dlieh != null)
- dlieh (this, args);
- }
-
- protected virtual void OnCancelCommand (DataListCommandEventArgs e)
- {
- InvokeCommandEvent (e, CancelCommandEvent);
- }
- protected virtual void OnDeleteCommand (DataListCommandEventArgs e)
- {
- InvokeCommandEvent (e, DeleteCommandEvent);
- }
- protected virtual void OnEditCommand (DataListCommandEventArgs e)
- {
- InvokeCommandEvent (e, EditCommandEvent);
- }
- protected virtual void OnItemCommand (DataListCommandEventArgs e)
- {
- InvokeCommandEvent (e, ItemCommandEvent);
- }
- protected virtual void OnItemCreated (DataListItemEventArgs e)
- {
- InvokeItemEvent (e, ItemCreatedEvent);
- }
- protected virtual void OnItemDataBound (DataListItemEventArgs e)
- {
- InvokeItemEvent (e, ItemDataBoundEvent);
- }
- protected virtual void OnUpdateCommand (DataListCommandEventArgs e)
- {
- InvokeCommandEvent (e, UpdateCommandEvent);
- }
- protected override void RenderContents (HtmlTextWriter writer)
- {
- if (Controls.Count == 0)
- return;
- RepeatInfo repeater = new RepeatInfo ();
- Table templateTable = null;
- if (extractTemplateRows) {
- repeater.RepeatDirection = RepeatDirection.Vertical;
- repeater.RepeatLayout = RepeatLayout.Flow;
- repeater.RepeatColumns = 1;
- repeater.OuterTableImplied = true;
-
- templateTable = new Table ();
- templateTable.ID = ClientID;
- templateTable.CopyBaseAttributes (this);
- templateTable.ApplyStyle (ControlStyle);
- templateTable.RenderBeginTag (writer);
- } else {
- repeater.RepeatDirection = RepeatDirection;
- repeater.RepeatLayout = RepeatLayout;
- repeater.RepeatColumns = RepeatColumns;
- }
- repeater.RenderRepeater (writer, this, ControlStyle, this);
- if (templateTable != null) {
- templateTable.RenderEndTag (writer);
- }
- }
- private DataListItem GetItem (ListItemType itemType, int repeatIndex)
- {
- DataListItem retVal = null;
- switch (itemType) {
- case ListItemType.Header:
- retVal = (DataListItem) Controls [0];
- break;
- case ListItemType.Footer:
- retVal = (DataListItem) Controls [Controls.Count - 1];
- break;
- case ListItemType.Item:
- goto case ListItemType.EditItem;
- case ListItemType.AlternatingItem:
- goto case ListItemType.EditItem;
- case ListItemType.SelectedItem:
- goto case ListItemType.EditItem;
- case ListItemType.EditItem:
- retVal = (DataListItem) itemsArray [repeatIndex];
- break;
- case ListItemType.Separator:
- int index = 2 * repeatIndex + 1;
- if (headerTemplate != null)
- index ++;
- retVal = (DataListItem) Controls [index];
- break;
- }
- return retVal;
- }
- /// <summary>
- /// Undocumented
- /// </summary>
- protected override void CreateControlHierarchy (bool useDataSource)
- {
- IEnumerable source = null;
- ArrayList dkeys = DataKeysArray;
- if (itemsArray != null) {
- itemsArray.Clear ();
- } else {
- itemsArray = new ArrayList ();
- }
- extractTemplateRows = ExtractTemplateRows;
- if (!useDataSource) {
- int count = (int) ViewState ["_!ItemCount"];
- if (count != -1) {
- source = new DataSourceInternal (count);
- itemsArray.Capacity = count;
- }
- } else {
- dkeys.Clear ();
- source = GetResolvedDataSource ();
- if (source is ICollection) {
- dkeys.Capacity = ((ICollection) source).Count;
- itemsArray.Capacity = ((ICollection) source).Count;
- }
- }
- int itemCount = 0;
- if (source != null) {
- int index = 0;
- int editIndex = EditItemIndex;
- int selIndex = SelectedIndex;
- string dataKey = DataKeyField;
-
- if (headerTemplate != null)
- CreateItem (-1, ListItemType.Header, useDataSource, null);
- foreach (object current in source) {
- if (useDataSource) {
- try {
- dkeys.Add (DataBinder.GetPropertyValue (current, dataKey));
- } catch {
- dkeys.Add (dkeys.Count);
- }
- }
- ListItemType type = ListItemType.Item;
- if (index == editIndex) {
- type = ListItemType.EditItem;
- } else if (index == selIndex) {
- type = ListItemType.SelectedItem;
- } else if ((index % 2) != 0) {
- type = ListItemType.AlternatingItem;
- }
- itemsArray.Add (CreateItem (index, type, useDataSource, current));
- if (separatorTemplate != null)
- CreateItem (index, ListItemType.Separator, useDataSource, null);
- itemCount++;
- index++;
- }
- if (footerTemplate != null)
- CreateItem (-1, ListItemType.Footer, useDataSource, null);
- }
- if (useDataSource)
- ViewState ["_!ItemCount"] = (source != null ? itemCount : -1);
- }
- /// <summary>
- /// Undocumented
- /// </summary>
- protected virtual DataListItem CreateItem (int itemIndex, ListItemType itemType)
- {
- return new DataListItem (itemIndex, itemType);
- }
- private DataListItem CreateItem (int itemIndex, ListItemType itemType, bool dataBind, object dataItem)
- {
- DataListItem retVal = CreateItem (itemIndex, itemType);
- DataListItemEventArgs e = new DataListItemEventArgs (retVal);
- InitializeItem (retVal);
- if (dataBind)
- retVal.DataItem = dataItem;
-
- OnItemCreated (e);
- Controls.Add (retVal);
- if (dataBind) {
- retVal.DataBind ();
- OnItemDataBound (e);
- retVal.DataItem = null;
- }
- return retVal;
- }
- /// <summary>
- /// Undocumented
- /// </summary>
- protected override void PrepareControlHierarchy ()
- {
- if (Controls.Count == 0)
- return;
- Style defaultStyle = null;
- Style rowStyle = null;
- if (alternatingItemStyle != null) {
- defaultStyle = new TableItemStyle ();
- defaultStyle.CopyFrom (itemStyle);
- defaultStyle.CopyFrom (alternatingItemStyle);
- } else {
- defaultStyle = itemStyle;
- }
- foreach (DataListItem current in Controls) {
- rowStyle = null;
- switch (current.ItemType) {
- case ListItemType.Header:
- if (headerStyle != null)
- rowStyle = headerStyle;
- break;
- case ListItemType.Footer:
- if (footerStyle != null)
- rowStyle = footerStyle;
- break;
- case ListItemType.Separator:
- rowStyle = separatorStyle;
- break;
- case ListItemType.Item:
- rowStyle = itemStyle;
- break;
- case ListItemType.AlternatingItem:
- rowStyle = defaultStyle;
- break;
- case ListItemType.SelectedItem:
- rowStyle = new TableItemStyle ();
- if ((current.ItemIndex % 2) == 0) {
- rowStyle.CopyFrom (itemStyle);
- } else {
- rowStyle.CopyFrom (defaultStyle);
- }
- rowStyle.CopyFrom (selectedItemStyle);
- break;
- case ListItemType.EditItem:
- rowStyle = new TableItemStyle ();
- if ((current.ItemIndex % 2) == 0) {
- rowStyle.CopyFrom (itemStyle);
- } else {
- rowStyle.CopyFrom (defaultStyle);
- }
- if (current.ItemIndex == SelectedIndex)
- rowStyle.CopyFrom (selectedItemStyle);
- rowStyle.CopyFrom (editItemStyle);
- break;
- }
- if (rowStyle == null)
- continue;
- if (!extractTemplateRows) {
- current.MergeStyle (rowStyle);
- continue;
- }
-
- if (current.HasControls ()) {
- int len = current.Controls.Count;
- for (int i = 0 ; i < len ; i++) {
- Control currentCtrl = current.Controls [i];
- if (!(currentCtrl is Table))
- continue;
- foreach (TableRow cRow in ((Table) currentCtrl).Rows)
- cRow.MergeStyle (rowStyle);
- }
- }
- }
- }
- /// <summary>
- /// Undocumented
- /// </summary>
- protected virtual void InitializeItem (DataListItem item)
- {
- ListItemType type = item.ItemType;
- ITemplate template = itemTemplate;
- switch (type) {
- case ListItemType.Header:
- template = headerTemplate;
- break;
- case ListItemType.Footer:
- template = footerTemplate;
- break;
- case ListItemType.AlternatingItem:
- if (alternatingItemTemplate != null)
- template = alternatingItemTemplate;
- break;
- case ListItemType.SelectedItem:
- if (selectedItemTemplate != null) {
- template = selectedItemTemplate;
- break;
- }
- if ((item.ItemIndex % 2) != 0)
- goto case ListItemType.AlternatingItem;
- break;
- case ListItemType.EditItem:
- if (editItemTemplate != null) {
- template = editItemTemplate;
- break;
- }
- if (item.ItemIndex == SelectedIndex)
- goto case ListItemType.SelectedItem;
- if ((item.ItemIndex % 2) != 0)
- goto case ListItemType.AlternatingItem;
- break;
- case ListItemType.Separator:
- template = separatorTemplate;
- break;
- }
- if (template != null)
- template.InstantiateIn (item);
- }
- bool IRepeatInfoUser.HasFooter {
- get { return (ShowFooter && footerTemplate != null); }
- }
- bool IRepeatInfoUser.HasHeader {
- get { return (ShowHeader && headerTemplate != null); }
- }
- bool IRepeatInfoUser.HasSeparators {
- get { return (separatorTemplate != null); }
- }
- int IRepeatInfoUser.RepeatedItemCount {
- get {
- if (itemsArray != null)
- return itemsArray.Count;
- return 0;
- }
- }
- void IRepeatInfoUser.RenderItem (ListItemType itemType,
- int repeatIndex,
- RepeatInfo repeatInfo,
- HtmlTextWriter writer)
- {
- DataListItem item = GetItem (itemType, repeatIndex);
- if (item != null)
- item.RenderItem (writer,
- extractTemplateRows,
- (repeatInfo.RepeatLayout == RepeatLayout.Table));
- }
- Style IRepeatInfoUser.GetItemStyle (ListItemType itemType, int repeatIndex)
- {
- DataListItem item = GetItem (itemType, repeatIndex);
- if (item == null || !item.ControlStyleCreated)
- return null;
- return item.ControlStyle;
- }
- }
- }
|