| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446 |
- //
- // System.Web.UI.WebControls.ListView
- //
- // Authors:
- // Marek Habersack ([email protected])
- //
- // (C) 2007-2008 Novell, Inc
- //
- //
- // 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.
- //
- #if NET_3_5
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Drawing;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- namespace System.Web.UI.WebControls
- {
- [DefaultEventAttribute ("SelectedIndexChanged")]
- [ControlValuePropertyAttribute ("SelectedValue")]
- [DesignerAttribute ("System.Web.UI.Design.WebControls.ListViewDesigner, System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
- [SupportsEventValidationAttribute ()]
- [ToolboxBitmapAttribute (typeof (ListView), "ListView.ico")]
- [DefaultPropertyAttribute ("SelectedValue")]
- public class ListView : DataBoundControl, INamingContainer, IPageableItemContainer
- {
- const int CSTATE_BASE_STATE = 0;
- const int CSTATE_DATAKEYNAMES = 1;
- const int CSTATE_DATAKEYSSTATE = 2;
- const int CSTATE_GROUPITEMCOUNT = 3;
- const int CSTATE_TOTALROWCOUNT = 4;
- const int CSTATE_EDITINDEX = 5;
- const int CSTATE_SELECTEDINDEX = 6;
- const int CSTATE_SORTDIRECTION = 7;
- const int CSTATE_SORTEXPRESSION = 8;
- const int CSTATE_COUNT = 9;
-
- ITemplate _emptyDataTemplate;
- ITemplate _emptyItemTemplate;
- ITemplate _insertItemTemplate;
- ITemplate _groupSeparatorTemplate;
- ITemplate _groupTemplate;
- ITemplate _itemSeparatorTemplate;
- ITemplate _itemTemplate;
- ITemplate _selectedItemTemplate;
- ITemplate _alternatingItemTemplate;
- ITemplate _editItemTemplate;
- ITemplate _layoutTemplate;
- int _totalRowCount;
- int _startRowIndex = -1;
- int _maximumRows = -1;
- int _selectedIndex;
- int _editIndex;
- int _groupItemCount;
- string [] _dataKeyNames;
- DataKeyArray _dataKeys;
- ArrayList _dataKeyArray;
- SortDirection _sortDirection = SortDirection.Ascending;
- string _sortExpression = String.Empty;
- Control _layoutTemplatePlaceholder;
- Control _nonGroupedItemsContainer;
- int _nonGroupedItemsContainerFirstItemIndex = -1;
- int _nonGroupedItemsContainerItemCount;
- IOrderedDictionary _lastInsertValues;
- #region Events
- // Event keys
- static readonly object ItemCancellingEvent = new object ();
- static readonly object ItemCommandEvent = new object ();
- static readonly object ItemCreatedEvent = new object ();
- static readonly object ItemDataBoundEvent = new object ();
- static readonly object ItemDeletedEvent = new object ();
- static readonly object ItemDeletingEvent = new object ();
- static readonly object ItemEditingEvent = new object ();
- static readonly object ItemInsertedEvent = new object ();
- static readonly object ItemInsertingEvent = new object ();
- static readonly object ItemUpdatedEvent = new object ();
- static readonly object ItemUpdatingEvent = new object ();
- static readonly object LayoutCreatedEvent = new object ();
- static readonly object PagePropertiesChangedEvent = new object ();
- static readonly object PagePropertiesChangingEvent = new object ();
- static readonly object SelectedIndexChangedEvent = new object ();
- static readonly object SelectedIndexChangingEvent = new object ();
- static readonly object SortedEvent = new object ();
- static readonly object SortingEvent = new object ();
- static readonly object TotalRowCountAvailableEvent = new object ();
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewCancelEventArgs> ItemCanceling {
- add { Events.AddHandler (ItemCancellingEvent, value); }
- remove { Events.RemoveHandler (ItemCancellingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewCommandEventArgs> ItemCommand {
- add { Events.AddHandler (ItemCommandEvent, value); }
- remove { Events.RemoveHandler (ItemCommandEvent, value); }
- }
-
- [CategoryAttribute ("Behavior")]
- public event EventHandler <ListViewItemEventArgs> ItemCreated {
- add { Events.AddHandler (ItemCreatedEvent, value); }
- remove { Events.RemoveHandler (ItemCreatedEvent, value); }
- }
-
- [CategoryAttribute ("Data")]
- public event EventHandler <ListViewItemEventArgs> ItemDataBound {
- add { Events.AddHandler (ItemDataBoundEvent, value); }
- remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewDeletedEventArgs> ItemDeleted {
- add { Events.AddHandler (ItemDeletedEvent, value); }
- remove { Events.RemoveHandler (ItemDeletedEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewDeleteEventArgs> ItemDeleting {
- add { Events.AddHandler (ItemDeletingEvent, value); }
- remove { Events.RemoveHandler (ItemDeletingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewEditEventArgs> ItemEditing {
- add { Events.AddHandler (ItemEditingEvent, value); }
- remove { Events.RemoveHandler (ItemEditingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewInsertedEventArgs> ItemInserted {
- add { Events.AddHandler (ItemInsertedEvent, value); }
- remove { Events.RemoveHandler (ItemInsertedEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewInsertEventArgs> ItemInserting {
- add { Events.AddHandler (ItemInsertingEvent, value); }
- remove { Events.RemoveHandler (ItemInsertingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewUpdatedEventArgs> ItemUpdated {
- add { Events.AddHandler (ItemUpdatedEvent, value); }
- remove { Events.RemoveHandler (ItemUpdatedEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewUpdateEventArgs> ItemUpdating {
- add { Events.AddHandler (ItemUpdatingEvent, value); }
- remove { Events.RemoveHandler (ItemUpdatingEvent, value); }
- }
-
- [CategoryAttribute ("Behavior")]
- public event EventHandler LayoutCreated {
- add { Events.AddHandler (LayoutCreatedEvent, value); }
- remove { Events.RemoveHandler (LayoutCreatedEvent, value); }
- }
-
- [CategoryAttribute ("Behavior")]
- public event EventHandler PagePropertiesChanged {
- add { Events.AddHandler (PagePropertiesChangedEvent, value); }
- remove { Events.RemoveHandler (PagePropertiesChangedEvent, value); }
- }
-
- [CategoryAttribute ("Behavior")]
- public event EventHandler <PagePropertiesChangingEventArgs> PagePropertiesChanging {
- add { Events.AddHandler (PagePropertiesChangingEvent, value); }
- remove { Events.RemoveHandler (PagePropertiesChangingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler SelectedIndexChanged {
- add { Events.AddHandler (SelectedIndexChangedEvent, value); }
- remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewSelectEventArgs> SelectedIndexChanging {
- add { Events.AddHandler (SelectedIndexChangingEvent, value); }
- remove { Events.RemoveHandler (SelectedIndexChangingEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler Sorted {
- add { Events.AddHandler (SortedEvent, value); }
- remove { Events.RemoveHandler (SortedEvent, value); }
- }
-
- [CategoryAttribute ("Action")]
- public event EventHandler <ListViewSortEventArgs> Sorting {
- add { Events.AddHandler (SortingEvent, value); }
- remove { Events.RemoveHandler (SortingEvent, value); }
- }
-
- event EventHandler <PageEventArgs> IPageableItemContainer.TotalRowCountAvailable {
- add { Events.AddHandler (TotalRowCountAvailableEvent, value); }
- remove { Events.RemoveHandler (TotalRowCountAvailableEvent, value); }
- }
- #endregion
- #region Properties
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- public override string AccessKey {
- get { return base.AccessKey; }
- set { throw StylingNotSupported (); }
- }
-
- [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValue (null)]
- [BrowsableAttribute (false)]
- public virtual ITemplate AlternatingItemTemplate {
- get { return _alternatingItemTemplate; }
- set { _alternatingItemTemplate = value; }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- public override Color BackColor {
- get { return base.BackColor; }
- set { throw StylingNotSupported (); }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- public override Color BorderColor {
- get { return base.BorderColor; }
- set { throw StylingNotSupported (); }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- public override BorderStyle BorderStyle {
- get { return base.BorderStyle; }
- set { throw StylingNotSupported (); }
- }
-
- [BrowsableAttribute (false)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public override Unit BorderWidth {
- get { return base.BorderWidth; }
- set { throw StylingNotSupported (); }
- }
-
- public override ControlCollection Controls {
- get {
- EnsureChildControls ();
- return base.Controls;
- }
- }
-
- [CategoryAttribute ("Behavior")]
- [DefaultValue (true)]
- public virtual bool ConvertEmptyStringToNull {
- get {
- object o = ViewState ["ConvertEmptyStringToNull"];
- if (o != null)
- return (bool) o;
- return true;
- }
-
- set { ViewState ["ConvertEmptyStringToNull"] = value; }
- }
-
- public override string CssClass {
- get { return base.CssClass; }
- set { throw StylingNotSupported (); }
- }
-
- [DefaultValue (null)]
- [TypeConverterAttribute (typeof (StringArrayConverter))]
- [CategoryAttribute ("Data")]
- public virtual string [] DataKeyNames {
- get {
- if (_dataKeyNames != null)
- return _dataKeyNames;
- return new string [0];
- }
- set {
- if (value == null)
- _dataKeyNames = null;
- else
- _dataKeyNames = (string []) value.Clone ();
- // They will eventually be recreated while creating the child controls
- _dataKeyArray = null;
- _dataKeys = null;
-
- if (Initialized)
- RequiresDataBinding = true;
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual DataKeyArray DataKeys {
- get {
- if (_dataKeys == null) {
- _dataKeys = new DataKeyArray (DataKeyArray);
- if (IsTrackingViewState)
- ((IStateManager) _dataKeys).TrackViewState ();
- }
- return _dataKeys;
- }
- }
- ArrayList DataKeyArray {
- get {
- if (_dataKeyArray == null)
- _dataKeyArray = new ArrayList ();
- return _dataKeyArray;
- }
- }
-
- [DefaultValue (-1)]
- [CategoryAttribute ("Misc")]
- public virtual int EditIndex {
- get { return _editIndex; }
- set {
- if (value < -1)
- throw new ArgumentOutOfRangeException ("value");
- if (value != _editIndex) {
- _editIndex = value;
- if (Initialized)
- RequiresDataBinding = true;
- }
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual ListViewItem EditItem {
- get { throw new NotImplementedException (); }
- }
-
- [DefaultValue (null)]
- [BrowsableAttribute (false)]
- [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- public virtual ITemplate EditItemTemplate {
- get { return _editItemTemplate; }
- set { _editItemTemplate = value; }
- }
-
- [DefaultValue (null)]
- [TemplateContainerAttribute (typeof (ListView))]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [BrowsableAttribute (false)]
- public virtual ITemplate EmptyDataTemplate {
- get { return _emptyDataTemplate; }
- set { _emptyDataTemplate = value; }
- }
-
- [TemplateContainerAttribute (typeof (ListViewItem))]
- [DefaultValue (null)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [BrowsableAttribute (false)]
- public virtual ITemplate EmptyItemTemplate {
- get { return _emptyItemTemplate; }
- set { _emptyItemTemplate = value; }
- }
-
- [BrowsableAttribute (false)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public override FontInfo Font {
- get { throw StylingNotSupported (); }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- public override Color ForeColor {
- get { return base.ForeColor; }
- set { throw StylingNotSupported (); }
- }
-
- [CategoryAttribute ("Misc")]
- [DefaultValue (1)]
- public virtual int GroupItemCount {
- get { return _groupItemCount; }
- set {
- if (value < 1)
- throw new ArgumentOutOfRangeException ("value");
- if (value != _groupItemCount) {
- _groupItemCount = value;
- if (Initialized)
- RequiresDataBinding = true;
- }
- }
- }
-
- [CategoryAttribute ("Behavior")]
- [DefaultValue ("groupPlaceholder")]
- public virtual string GroupPlaceholderID {
- get {
- string s = ViewState ["GroupPlaceholderID"] as string;
- if (s != null)
- return s;
- return "groupPlaceHolder";
- }
-
- set {
- if (String.IsNullOrEmpty (value))
- throw new ArgumentOutOfRangeException ("value");
- ViewState ["GroupPlaceholderID"] = value;
- }
- }
-
- [BrowsableAttribute (false)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValue (null)]
- [TemplateContainerAttribute (typeof (ListViewItem))]
- public virtual ITemplate GroupSeparatorTemplate {
- get { return _groupSeparatorTemplate; }
- set { _groupSeparatorTemplate = value; }
- }
-
- [TemplateContainerAttribute (typeof (ListViewItem))]
- [DefaultValue (null)]
- [BrowsableAttribute (false)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- public virtual ITemplate GroupTemplate {
- get { return _groupTemplate; }
- set { _groupTemplate = value; }
- }
-
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public override Unit Height {
- get { return base.Height; }
- set { throw StylingNotSupported (); }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual ListViewItem InsertItem {
- get;
- private set;
- }
-
- [CategoryAttribute ("Misc")]
- [DefaultValue (InsertItemPosition.None)]
- public virtual InsertItemPosition InsertItemPosition {
- get;
- set;
- }
-
- [TemplateContainerAttribute (typeof (ListViewItem), BindingDirection.TwoWay)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValue (null)]
- [BrowsableAttribute (false)]
- public virtual ITemplate InsertItemTemplate {
- get { return _insertItemTemplate; }
- set { _insertItemTemplate = value; }
- }
-
- [DefaultValue ("itemPlaceholder")]
- [CategoryAttribute ("Behavior")]
- public virtual string ItemPlaceholderID {
- get {
- string s = ViewState ["ItemPlaceHolderID"] as string;
- if (s != null)
- return s;
- return "itemPlaceholder";
- }
-
- set {
- if (String.IsNullOrEmpty (value))
- throw new ArgumentOutOfRangeException ("value");
-
- ViewState ["ItemPlaceHolderID"] = value;
- }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual IList <ListViewDataItem> Items {
- get { throw new NotImplementedException (); }
- }
-
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [BrowsableAttribute (false)]
- [TemplateContainerAttribute (typeof (ListViewItem))]
- [DefaultValue (null)]
- public virtual ITemplate ItemSeparatorTemplate {
- get { return _itemSeparatorTemplate; }
- set { _itemSeparatorTemplate = value; }
- }
-
- [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
- [DefaultValue (null)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [BrowsableAttribute (false)]
- public virtual ITemplate ItemTemplate {
- get { return _itemTemplate; }
- set { _itemTemplate = value; }
- }
-
- [TemplateContainerAttribute (typeof (ListView))]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValue (null)]
- [BrowsableAttribute (false)]
- public virtual ITemplate LayoutTemplate {
- get { return _layoutTemplate; }
- set { _layoutTemplate = value; }
- }
-
- protected virtual int MaximumRows {
- get { return _maximumRows; }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual DataKey SelectedDataKey {
- get {
- if (_dataKeyNames == null || _dataKeyNames.Length == 0)
- throw new InvalidOperationException ("No data keys are specified in the DataKeyNames property.");
- DataKeyArray dataKeys = DataKeys;
- int selIndex = SelectedIndex;
- if (selIndex > -1 || selIndex < dataKeys.Count)
- return dataKeys [selIndex];
- return null;
- }
- }
-
- [CategoryAttribute ("Misc")]
- [DefaultValue (-1)]
- public virtual int SelectedIndex {
- get { return _selectedIndex; }
- set {
- if (value < -1)
- throw new ArgumentOutOfRangeException ("value");
- if (value != _selectedIndex) {
- _selectedIndex = value;
- if (Initialized)
- RequiresDataBinding = true;
- }
- }
- }
-
- [BrowsableAttribute (false)]
- [DefaultValue (null)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
- public virtual ITemplate SelectedItemTemplate {
- get { return _selectedItemTemplate; }
- set { _selectedItemTemplate = value; }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public object SelectedValue {
- get {
- DataKey dk = SelectedDataKey;
- if (dk != null)
- return dk.Value;
- return null;
- }
- }
-
- [DefaultValue (SortDirection.Ascending)]
- [BrowsableAttribute (false)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual SortDirection SortDirection {
- get { return _sortDirection; }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual string SortExpression {
- get { return _sortExpression; }
- }
-
- protected virtual int StartRowIndex {
- get {
- if (_startRowIndex < 0)
- return 0;
-
- return _startRowIndex;
- }
- }
-
- int IPageableItemContainer.MaximumRows {
- get { return MaximumRows; }
- }
-
- int IPageableItemContainer.StartRowIndex {
- get { return StartRowIndex; }
- }
-
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public override short TabIndex {
- get { return 0; }
- set { throw new NotSupportedException ("ListView does not allow setting this property."); }
- }
-
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public override string ToolTip {
- get { return base.ToolTip; }
- set { throw StylingNotSupported (); }
- }
-
- [EditorBrowsableAttribute (EditorBrowsableState.Never)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public override Unit Width {
- get { return base.Width; }
- set { throw StylingNotSupported (); }
- }
- #endregion
-
- public ListView ()
- {
- InsertItemPosition = InsertItemPosition.None;
- ResetDefaults ();
- }
- void ResetDefaults ()
- {
- _totalRowCount = -1;
- _selectedIndex = -1;
- _editIndex = -1;
- _groupItemCount = -1;
- }
-
- protected virtual void AddControlToContainer (Control control, Control container, int addLocation)
- {
- if (control == null || container == null)
- return;
- Control ctl;
- if (container is HtmlTable) {
- ctl = new ListViewTableRow ();
- ctl.Controls.Add (control);
- } else
- ctl = control;
-
- container.Controls.AddAt (addLocation, ctl);
- }
-
- protected internal override void CreateChildControls ()
- {
- object itemCount = ViewState ["_!ItemCount"];
- if (itemCount != null) {
- if (RequiresDataBinding)
- EnsureDataBound ();
- int c = (int)itemCount;
- if (c >= 0) {
- // Fake data - we only need to make sure
- // OnTotalRowCountAvailable is called now - so that any
- // pagers can create child controls.
- object[] data = new object [c];
- CreateChildControls (data, false);
- }
- }
-
- base.CreateChildControls ();
- }
-
- protected virtual int CreateChildControls (IEnumerable dataSource, bool dataBinding)
- {
- IList <ListViewDataItem> retList = null;
- EnsureLayoutTemplate ();
- RemoveItems ();
- // If any of the _maximumRows or _startRowIndex is different to their
- // defaults, it means we are paging - i.e. SetPageProperties has been
- // called.
- bool haveDataToPage = _maximumRows > 0 || _startRowIndex > 0;
- var pagedDataSource = new ListViewPagedDataSource ();
-
- if (dataBinding) {
- DataSourceView view = GetData ();
- if (view == null)
- throw new InvalidOperationException ("dataSource returned a null reference for DataSourceView.");
- int totalRowCount = 0;
- if (haveDataToPage && view.CanPage) {
- if (view.CanRetrieveTotalRowCount)
- totalRowCount = SelectArguments.TotalRowCount;
- else {
- ICollection ds = dataSource as ICollection;
- if (ds == null)
- throw new InvalidOperationException ("dataSource does not implement the ICollection interface.");
- totalRowCount = ds.Count + StartRowIndex;
- }
- }
- pagedDataSource.TotalRowCount = totalRowCount;
- DataKeyArray.Clear ();
- } else {
- if (!(dataSource is ICollection))
- throw new InvalidOperationException ("dataSource does not implement the ICollection interface and dataBinding is false.");
- pagedDataSource.TotalRowCount = 0;
- }
- pagedDataSource.StartRowIndex = StartRowIndex;
- pagedDataSource.MaximumRows = MaximumRows;
- pagedDataSource.DataSource = dataSource;
-
- bool emptySet = false;
- if (dataSource != null) {
- if (GroupItemCount <= 0)
- retList = CreateItemsWithoutGroups (pagedDataSource, dataBinding, InsertItemPosition, DataKeyArray);
- if (InsertItemPosition != InsertItemPosition.None && (retList == null || (retList != null && retList.Count == 0)))
- emptySet = true;
- if (haveDataToPage)
- // Data source has paged data for us, so we must use its total row
- // count
- _totalRowCount = pagedDataSource.DataSourceCount;
- else if (!emptySet)
- _totalRowCount = retList.Count;
- else
- _totalRowCount = 0;
- OnTotalRowCountAvailable (new PageEventArgs (_startRowIndex, _maximumRows, _totalRowCount));
- } else
- emptySet = true;
- if (emptySet) {
- Controls.Clear ();
- CreateEmptyItem ();
- }
-
- if (retList == null)
- return 0;
- return _totalRowCount;
- }
-
- protected override Style CreateControlStyle ()
- {
- throw StylingNotSupported ();
- }
-
- protected virtual ListViewDataItem CreateDataItem (int dataItemIndex, int displayIndex)
- {
- return new ListViewDataItem (dataItemIndex, displayIndex);
- }
-
- protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
- {
- DataSourceSelectArguments arg = DataSourceSelectArguments.Empty;
- DataSourceView view = GetData();
-
- if (view.CanPage) {
- arg.StartRowIndex = _startRowIndex;
- if (view.CanRetrieveTotalRowCount) {
- arg.RetrieveTotalRowCount = true;
- arg.MaximumRows = _maximumRows;
- } else
- arg.MaximumRows = -1;
- }
- if (IsBoundUsingDataSourceID && !String.IsNullOrEmpty (_sortExpression)) {
- if (_sortDirection == SortDirection.Ascending)
- arg.SortExpression = _sortExpression;
- else
- arg.SortExpression = _sortExpression + " DESC";
- }
-
- return arg;
- }
-
- protected virtual void CreateEmptyDataItem ()
- {
- if (_emptyDataTemplate != null) {
- ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
- InstantiateEmptyDataTemplate (item);
- OnItemCreated (new ListViewItemEventArgs (item));
- AddControlToContainer (item, this, 0);
- }
- }
-
- protected virtual ListViewItem CreateEmptyItem ()
- {
- if (_emptyDataTemplate != null) {
- ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
- InstantiateEmptyItemTemplate (item);
- OnItemCreated (new ListViewItemEventArgs (item));
- return item;
- }
- return null;
- }
-
- protected virtual ListViewItem CreateInsertItem ()
- {
- ListViewItem ret = CreateItem (ListViewItemType.InsertItem);
- InsertItem = ret;
- return ret;
- }
-
- protected virtual ListViewItem CreateItem (ListViewItemType itemType)
- {
- return new ListViewItem (itemType);
- }
-
- protected virtual IList <ListViewDataItem> CreateItemsInGroups (ListViewPagedDataSource dataSource, bool dataBinding, InsertItemPosition insertPosition,
- ArrayList keyArray)
- {
- if (_groupTemplate == null)
- return null;
-
- throw new NotImplementedException ();
- }
-
- protected virtual IList <ListViewDataItem> CreateItemsWithoutGroups (ListViewPagedDataSource dataSource, bool dataBinding,
- InsertItemPosition insertPosition, ArrayList keyArray)
- {
- if (_nonGroupedItemsContainer == null)
- _nonGroupedItemsContainer = FindPlaceholder (ItemPlaceholderID, this);
- _nonGroupedItemsContainerItemCount = 0;
-
- if (_nonGroupedItemsContainer == null)
- throw new InvalidOperationException (
- String.Format ("An item placeholder must be specified on ListView '{0}'. Specify an item placeholder by setting a control's ID property to \"itemPlaceholder\". The item placeholder control must also specify runat=\"server\".", ID));
- Control parent = _nonGroupedItemsContainer.Parent;
- int ipos;
- if (_nonGroupedItemsContainerFirstItemIndex == -1) {
- ipos = 0;
- if (parent != null) {
- ipos = parent.Controls.IndexOf (_nonGroupedItemsContainer);
- parent.Controls.Remove (_nonGroupedItemsContainer);
- _nonGroupedItemsContainer = parent;
- if (_nonGroupedItemsContainer != _layoutTemplatePlaceholder)
- AddControlToContainer (_nonGroupedItemsContainer, _layoutTemplatePlaceholder, 0);
- }
- _nonGroupedItemsContainerFirstItemIndex = ipos;
- } else
- ipos = _nonGroupedItemsContainerFirstItemIndex;
-
- List <ListViewDataItem> ret = new List <ListViewDataItem> ();
- ListViewItem lvi;
- ListViewItem container;
- bool needSeparator = false;
- if (insertPosition == InsertItemPosition.FirstItem) {
- lvi = CreateInsertItem ();
- InstantiateInsertItemTemplate (lvi);
- AddControlToContainer (lvi, _nonGroupedItemsContainer, ipos++);
- _nonGroupedItemsContainerItemCount++;
- needSeparator = true;
- }
- bool haveSeparatorTemplate = _itemSeparatorTemplate != null;
- int displayIndex = 0;
- ListViewDataItem lvdi;
- int startIndex = dataSource.StartRowIndex;
- foreach (object item in dataSource) {
- if (needSeparator && haveSeparatorTemplate) {
- container = new ListViewItem ();
- InstantiateItemSeparatorTemplate (container);
- AddControlToContainer (container, _nonGroupedItemsContainer, ipos++);
- _nonGroupedItemsContainerItemCount++;
- }
- lvdi = CreateDataItem (startIndex + displayIndex, displayIndex);
- InstantiateItemTemplate (lvdi, displayIndex);
- if (dataBinding) {
- lvdi.DataItem = item;
- OrderedDictionary dict = new OrderedDictionary ();
- string[] dataKeyNames = DataKeyNames;
-
- foreach (string s in dataKeyNames)
- dict.Add (s, DataBinder.GetPropertyValue (item, s));
-
- DataKey dk = new DataKey (dict, dataKeyNames);
- if (keyArray.Count == displayIndex)
- keyArray.Add (dk);
- else
- keyArray [displayIndex] = dk;
- }
-
- OnItemCreated (new ListViewItemEventArgs (lvdi));
- AddControlToContainer (lvdi, _nonGroupedItemsContainer, ipos++);
- _nonGroupedItemsContainerItemCount++;
-
- if (!needSeparator)
- needSeparator = true;
- if (dataBinding) {
- lvdi.DataBind ();
- OnItemDataBound (new ListViewItemEventArgs (lvdi));
- }
- displayIndex++;
- ret.Add (lvdi);
- }
- if (insertPosition == InsertItemPosition.LastItem) {
- if (needSeparator && haveSeparatorTemplate) {
- container = new ListViewItem ();
- InstantiateItemSeparatorTemplate (container);
- AddControlToContainer (container, _nonGroupedItemsContainer, ipos++);
- _nonGroupedItemsContainerItemCount++;
- }
-
- lvi = CreateInsertItem ();
- InstantiateInsertItemTemplate (lvi);
- AddControlToContainer (lvi, _nonGroupedItemsContainer, ipos++);
- _nonGroupedItemsContainerItemCount++;
- }
-
- return ret;
- }
-
- protected virtual void CreateLayoutTemplate ()
- {
- if (_layoutTemplate != null) {
- _layoutTemplatePlaceholder = new Control ();
- _layoutTemplate.InstantiateIn (_layoutTemplatePlaceholder);
- Controls.Add (_layoutTemplatePlaceholder);
- }
-
- OnLayoutCreated (EventArgs.Empty);
- }
-
- public virtual void DeleteItem (int itemIndex)
- {
- }
-
- protected virtual void EnsureLayoutTemplate ()
- {
- if (Controls.Count != 0)
- return;
-
- CreateLayoutTemplate ();
- }
-
- public virtual void ExtractItemValues (IOrderedDictionary itemValues, ListViewItem item, bool includePrimaryKey)
- {
- if (itemValues == null)
- throw new ArgumentNullException ("itemValues");
-
- if (!(item is ListViewDataItem))
- throw new InvalidOperationException ("item is not a ListViewDataItem object.");
- }
- protected virtual Control FindPlaceholder (string containerID, Control container)
- {
- if (container == null || String.IsNullOrEmpty (containerID))
- return null;
- return container.FindControl (containerID);
- }
-
- public virtual void InsertNewItem (bool causesValidation)
- {
- ListViewItem insertItem = InsertItem;
- if (insertItem == null)
- throw new InvalidOperationException ("The ListView control does not have an insert item.");
- DataSourceView dsv = null;
- ListViewInsertEventArgs eventArgs = null;
-
- if (IsBoundUsingDataSourceID) {
- dsv = GetData ();
- if (dsv == null)
- throw new InvalidOperationException ("Missing data.");
- eventArgs = new ListViewInsertEventArgs (insertItem);
- ExtractItemValues (eventArgs.Values, insertItem, true);
- } else
- eventArgs = new ListViewInsertEventArgs (insertItem);
- OnItemInserting (eventArgs);
- if (!eventArgs.Cancel && IsBoundUsingDataSourceID) {
- _lastInsertValues = eventArgs.Values;
- dsv.Insert (_lastInsertValues, new DataSourceViewOperationCallback (InsertNewItemCallback));
- }
- }
- bool InsertNewItemCallback (int recordsAffected, Exception ex)
- {
- var eventArgs = new ListViewInsertedEventArgs (_lastInsertValues, recordsAffected, ex);
- OnItemInserted (eventArgs);
- _lastInsertValues = null;
- if (ex != null && !eventArgs.ExceptionHandled)
- return false;
- // This will effectively reset the insert values
- if (!eventArgs.KeepInInsertMode)
- RequiresDataBinding = true;
- return true;
- }
-
- protected virtual void InstantiateEmptyDataTemplate (Control container)
- {
- if (_emptyDataTemplate != null)
- _emptyDataTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateEmptyItemTemplate (Control container)
- {
- if (_emptyItemTemplate != null)
- _emptyItemTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateGroupSeparatorTemplate (Control container)
- {
- if (_groupSeparatorTemplate != null)
- _groupSeparatorTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateGroupTemplate (Control container)
- {
- if (_groupTemplate != null)
- _groupTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateInsertItemTemplate (Control container)
- {
- if (_insertItemTemplate != null)
- _insertItemTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateItemSeparatorTemplate (Control container)
- {
- if (_itemSeparatorTemplate != null)
- _itemSeparatorTemplate.InstantiateIn (container);
- }
-
- protected virtual void InstantiateItemTemplate (Control container, int displayIndex)
- {
- if (_itemTemplate == null)
- throw new InvalidOperationException ("ItemTemplate is missing");
- ITemplate template = _itemTemplate;
- if ((displayIndex % 2 != 0) && _alternatingItemTemplate != null)
- template = _alternatingItemTemplate;
-
- if ((displayIndex == _selectedIndex) && _selectedItemTemplate != null)
- template = _selectedItemTemplate;
- if ((displayIndex == _editIndex) && _editItemTemplate != null)
- template = _editItemTemplate;
- template.InstantiateIn (container);
- }
- void LoadDataKeysState (object savedState)
- {
- object[] state = savedState as object[];
- int len = state != null ? state.Length : 0;
- if (len == 0)
- return;
- ArrayList dataKeyArray = DataKeyArray;
- DataKey dk;
- string[] keyNames = DataKeyNames;
-
- for (int i = 0; i < len; i++) {
- dk = new DataKey (new OrderedDictionary (), keyNames);
- ((IStateManager)dk).LoadViewState (state [i]);
- dataKeyArray.Add (dk);
- }
- _dataKeys = null;
- }
-
- protected override void LoadControlState (object savedState)
- {
- ResetDefaults ();
- object[] state = savedState as object[];
- if (state == null || state.Length != CSTATE_COUNT)
- return;
-
- object o;
- base.LoadControlState (state [CSTATE_BASE_STATE]);
- if ((o = state [CSTATE_DATAKEYNAMES]) != null)
- DataKeyNames = (string[])o;
- LoadDataKeysState (state [CSTATE_DATAKEYSSTATE]);
- if ((o = state [CSTATE_GROUPITEMCOUNT]) != null)
- GroupItemCount = (int)o;
- if ((o = state [CSTATE_TOTALROWCOUNT]) != null)
- _totalRowCount = (int)o;
- if ((o = state [CSTATE_EDITINDEX]) != null)
- EditIndex = (int)o;
- if ((o = state [CSTATE_SELECTEDINDEX]) != null)
- SelectedIndex = (int)o;
- if ((o = state [CSTATE_SORTDIRECTION]) != null)
- _sortDirection = (SortDirection)o;
- if ((o = state [CSTATE_SORTEXPRESSION]) != null)
- _sortExpression = (string)o;
- }
-
- protected override void LoadViewState (object savedState)
- {
- object[] state = savedState as object[];
- int len = state != null ? state.Length : 0;
- if (len == 0)
- return;
- base.LoadViewState (state [0]);
- }
-
- protected override bool OnBubbleEvent (object source, EventArgs e)
- {
- ListViewCommandEventArgs args = e as ListViewCommandEventArgs;
- if (args != null) {
- bool causesValidation = false;
- IButtonControl button = args.CommandSource as IButtonControl;
- if (button != null && button.CausesValidation) {
- Page.Validate (button.ValidationGroup);
- causesValidation = true;
- }
- ProcessCommand (args, causesValidation);
- return true;
- }
- return base.OnBubbleEvent (source, e);
- }
- void ProcessCommand (ListViewCommandEventArgs args, bool causesValidation)
- {
- OnItemCommand (args);
- }
-
- protected override void OnInit (EventArgs e)
- {
- Page.RegisterRequiresControlState (this);
- base.OnInit (e);
- }
- void InvokeEvent <T> (object key, T args) where T : EventArgs
- {
- EventHandlerList events = Events;
- if (events != null) {
- EventHandler <T> eh = events [key] as EventHandler <T>;
- if (eh != null)
- eh (this, args);
- }
- }
- void InvokeEvent (object key, EventArgs args)
- {
- EventHandlerList events = Events;
- if (events != null) {
- EventHandler eh = events [key] as EventHandler;
- if (eh != null)
- eh (this, args);
- }
- }
-
- protected virtual void OnItemCanceling (ListViewCancelEventArgs e)
- {
- InvokeEvent <ListViewCancelEventArgs> (ItemCancellingEvent, e);
- }
-
- protected virtual void OnItemCommand (ListViewCommandEventArgs e)
- {
- InvokeEvent <ListViewCommandEventArgs> (ItemCommandEvent, e);
- }
-
- protected virtual void OnItemCreated (ListViewItemEventArgs e)
- {
- InvokeEvent <ListViewItemEventArgs> (ItemCreatedEvent, e);
- }
-
- protected virtual void OnItemDataBound (ListViewItemEventArgs e)
- {
- InvokeEvent <ListViewItemEventArgs> (ItemDataBoundEvent, e);
- }
-
- protected virtual void OnItemDeleted (ListViewDeletedEventArgs e)
- {
- InvokeEvent <ListViewDeletedEventArgs> (ItemDeletedEvent, e);
- }
-
- protected virtual void OnItemDeleting (ListViewDeleteEventArgs e)
- {
- InvokeEvent <ListViewDeleteEventArgs> (ItemDeletingEvent, e);
- }
-
- protected virtual void OnItemEditing (ListViewEditEventArgs e)
- {
- InvokeEvent <ListViewEditEventArgs> (ItemEditingEvent, e);
- }
-
- protected virtual void OnItemInserted (ListViewInsertedEventArgs e)
- {
- InvokeEvent <ListViewInsertedEventArgs> (ItemInsertedEvent, e);
- }
-
- protected virtual void OnItemInserting (ListViewInsertEventArgs e)
- {
- InvokeEvent <ListViewInsertEventArgs> (ItemInsertingEvent, e);
- }
-
- protected virtual void OnItemUpdated (ListViewUpdatedEventArgs e)
- {
- InvokeEvent <ListViewUpdatedEventArgs> (ItemUpdatedEvent, e);
- }
-
- protected virtual void OnItemUpdating (ListViewUpdateEventArgs e)
- {
- InvokeEvent <ListViewUpdateEventArgs> (ItemUpdatingEvent, e);
- }
-
- protected virtual void OnLayoutCreated (EventArgs e)
- {
- InvokeEvent (LayoutCreatedEvent, e);
- }
-
- protected virtual void OnPagePropertiesChanged (EventArgs e)
- {
- InvokeEvent (PagePropertiesChangedEvent, e);
- }
-
- protected virtual void OnPagePropertiesChanging (PagePropertiesChangingEventArgs e)
- {
- InvokeEvent (PagePropertiesChangingEvent, e);
- }
-
- protected virtual void OnSelectedIndexChanged (EventArgs e)
- {
- InvokeEvent (SelectedIndexChangedEvent, e);
- }
-
- protected virtual void OnSelectedIndexChanging (ListViewSelectEventArgs e)
- {
- InvokeEvent (SelectedIndexChangingEvent, e);
- }
-
- protected virtual void OnSorted (EventArgs e)
- {
- InvokeEvent (SortedEvent, e);
- }
-
- protected virtual void OnSorting (ListViewSortEventArgs e)
- {
- InvokeEvent <ListViewSortEventArgs> (SortingEvent, e);
- }
-
- protected virtual void OnTotalRowCountAvailable (PageEventArgs e)
- {
- InvokeEvent <PageEventArgs> (TotalRowCountAvailableEvent, e);
- }
-
- protected override void PerformDataBinding (IEnumerable data)
- {
- base.PerformDataBinding (data);
- TrackViewState ();
- int childCount = CreateChildControls (data, true);
- ChildControlsCreated = true;
- ViewState ["_!ItemCount"] = childCount;
- }
-
- protected override void PerformSelect ()
- {
- EnsureLayoutTemplate ();
- base.PerformSelect ();
- }
-
- protected virtual void RemoveItems ()
- {
- if (_nonGroupedItemsContainer != null)
- RemoveItems (_nonGroupedItemsContainer, _nonGroupedItemsContainerFirstItemIndex, _nonGroupedItemsContainerItemCount);
- }
- void RemoveItems (Control container, int start, int count)
- {
- int i = count;
- while (i-- > 0)
- container.Controls.RemoveAt (start);
- }
-
- protected override void Render (HtmlTextWriter writer)
- {
- base.Render (writer);
- // Why override?
- }
- object SaveDataKeysState ()
- {
- DataKeyArray dka = DataKeys;
- int len = dka != null ? dka.Count : 0;
- if (len == 0)
- return null;
- object[] state = new object [len];
- DataKey dk;
- for (int i = 0; i < len; i++) {
- dk = dka [i];
- if (dk == null) {
- state [i] = null;
- continue;
- }
- state [i] = ((IStateManager)dk).SaveViewState ();
- }
-
- return state;
- }
-
- protected override object SaveControlState ()
- {
- object[] ret = new object [CSTATE_COUNT];
- string[] dataKeyNames = DataKeyNames;
- object dataKeysState = SaveDataKeysState ();
-
- ret [CSTATE_BASE_STATE] = base.SaveControlState ();
- ret [CSTATE_DATAKEYNAMES] = dataKeyNames.Length > 0 ? dataKeyNames : null;
- ret [CSTATE_DATAKEYSSTATE] = dataKeysState != null ? dataKeysState : null;
- ret [CSTATE_GROUPITEMCOUNT] = _groupItemCount > 1 ? (object)_groupItemCount : null;
- ret [CSTATE_TOTALROWCOUNT] = _totalRowCount >= 1 ? (object)_totalRowCount : null;
- ret [CSTATE_EDITINDEX] = _editIndex != -1 ? (object)_editIndex : null;
- ret [CSTATE_SELECTEDINDEX] = _selectedIndex != -1 ? (object)_selectedIndex : null;
- ret [CSTATE_SORTDIRECTION] = _sortDirection != SortDirection.Ascending ? (object)_sortDirection : null;
- ret [CSTATE_SORTEXPRESSION] = String.IsNullOrEmpty (_sortExpression) ? null : _sortExpression;
-
- return ret;
- }
-
- protected override object SaveViewState ()
- {
- object[] states = new object [2];
- states [0] = base.SaveViewState ();
- states [1] = null; // What goes here?
-
- return states;
- }
-
- protected virtual void SetPageProperties (int startRowIndex, int maximumRows, bool databind)
- {
- if (maximumRows < 1)
- throw new ArgumentOutOfRangeException ("maximumRows");
- if (startRowIndex < 0)
- throw new ArgumentOutOfRangeException ("startRowIndex");
- if (maximumRows != _maximumRows || startRowIndex != _startRowIndex) {
- if (databind) {
- var args = new PagePropertiesChangingEventArgs (maximumRows, startRowIndex);
- OnPagePropertiesChanging (args);
- }
- _startRowIndex = startRowIndex;
- _maximumRows = maximumRows;
- if (databind)
- OnPagePropertiesChanged (EventArgs.Empty);
- }
- if (databind)
- RequiresDataBinding = true;
- }
-
- public virtual void Sort (string sortExpression, SortDirection sortDirection)
- {
- }
-
- void IPageableItemContainer.SetPageProperties (int startRowIndex, int maximumRows, bool databind)
- {
- SetPageProperties (startRowIndex, maximumRows, databind);
- }
-
- public virtual void UpdateItem (int itemIndex, bool causesValidation)
- {
- }
-
- NotSupportedException StylingNotSupported ()
- {
- return new NotSupportedException ("Style properties are not supported on ListView. Apply styling or CSS classes to the elements in the ListView's templates.");
- }
- }
- }
- #endif
|