ListView.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. //
  2. // System.Web.UI.WebControls.ListView
  3. //
  4. // Authors:
  5. // Marek Habersack ([email protected])
  6. //
  7. // (C) 2007-2008 Novell, Inc
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_3_5
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using System.Collections.Specialized;
  34. using System.ComponentModel;
  35. using System.Drawing;
  36. using System.Web;
  37. using System.Web.UI;
  38. using System.Web.UI.HtmlControls;
  39. namespace System.Web.UI.WebControls
  40. {
  41. [DefaultEventAttribute ("SelectedIndexChanged")]
  42. [ControlValuePropertyAttribute ("SelectedValue")]
  43. [DesignerAttribute ("System.Web.UI.Design.WebControls.ListViewDesigner, System.Web.Extensions.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")]
  44. [SupportsEventValidationAttribute ()]
  45. [ToolboxBitmapAttribute (typeof (ListView), "ListView.ico")]
  46. [DefaultPropertyAttribute ("SelectedValue")]
  47. public class ListView : DataBoundControl, INamingContainer, IPageableItemContainer
  48. {
  49. ITemplate _emptyDataTemplate;
  50. ITemplate _emptyItemTemplate;
  51. ITemplate _insertItemTemplate;
  52. ITemplate _groupSeparatorTemplate;
  53. ITemplate _groupTemplate;
  54. ITemplate _itemSeparatorTemplate;
  55. ITemplate _itemTemplate;
  56. ITemplate _selectedItemTemplate;
  57. ITemplate _alternatingItemTemplate;
  58. ITemplate _editItemTemplate;
  59. ITemplate _layoutTemplate;
  60. int _startRowIndex;
  61. int _maximumRows;
  62. int _selectedIndex;
  63. int _editIndex;
  64. int _groupItemCount;
  65. string [] _dataKeyNames;
  66. DataKeyArray _dataKeys;
  67. ArrayList _dataKeyArray;
  68. SortDirection _sortDirection = SortDirection.Ascending;
  69. string _sortExpression = String.Empty;
  70. Control _layoutTemplatePlaceholder;
  71. Control _nonGroupedItemsContainer;
  72. int _nonGroupedItemsContainerFirstItemIndex;
  73. int _nonGroupedItemsContainerItemCount;
  74. IOrderedDictionary _lastInsertValues;
  75. #region Events
  76. // Event keys
  77. static readonly object ItemCancellingEvent = new object ();
  78. static readonly object ItemCommandEvent = new object ();
  79. static readonly object ItemCreatedEvent = new object ();
  80. static readonly object ItemDataBoundEvent = new object ();
  81. static readonly object ItemDeletedEvent = new object ();
  82. static readonly object ItemDeletingEvent = new object ();
  83. static readonly object ItemEditingEvent = new object ();
  84. static readonly object ItemInsertedEvent = new object ();
  85. static readonly object ItemInsertingEvent = new object ();
  86. static readonly object ItemUpdatedEvent = new object ();
  87. static readonly object ItemUpdatingEvent = new object ();
  88. static readonly object LayoutCreatedEvent = new object ();
  89. static readonly object PagePropertiesChangedEvent = new object ();
  90. static readonly object PagePropertiesChangingEvent = new object ();
  91. static readonly object SelectedIndexChangedEvent = new object ();
  92. static readonly object SelectedIndexChangingEvent = new object ();
  93. static readonly object SortedEvent = new object ();
  94. static readonly object SortingEvent = new object ();
  95. static readonly object TotalRowCountAvailableEvent = new object ();
  96. [CategoryAttribute ("Action")]
  97. public event EventHandler <ListViewCancelEventArgs> ItemCanceling {
  98. add { Events.AddHandler (ItemCancellingEvent, value); }
  99. remove { Events.RemoveHandler (ItemCancellingEvent, value); }
  100. }
  101. [CategoryAttribute ("Action")]
  102. public event EventHandler <ListViewCommandEventArgs> ItemCommand {
  103. add { Events.AddHandler (ItemCommandEvent, value); }
  104. remove { Events.RemoveHandler (ItemCommandEvent, value); }
  105. }
  106. [CategoryAttribute ("Behavior")]
  107. public event EventHandler <ListViewItemEventArgs> ItemCreated {
  108. add { Events.AddHandler (ItemCreatedEvent, value); }
  109. remove { Events.RemoveHandler (ItemCreatedEvent, value); }
  110. }
  111. [CategoryAttribute ("Data")]
  112. public event EventHandler <ListViewItemEventArgs> ItemDataBound {
  113. add { Events.AddHandler (ItemDataBoundEvent, value); }
  114. remove { Events.RemoveHandler (ItemDataBoundEvent, value); }
  115. }
  116. [CategoryAttribute ("Action")]
  117. public event EventHandler <ListViewDeletedEventArgs> ItemDeleted {
  118. add { Events.AddHandler (ItemDeletedEvent, value); }
  119. remove { Events.RemoveHandler (ItemDeletedEvent, value); }
  120. }
  121. [CategoryAttribute ("Action")]
  122. public event EventHandler <ListViewDeleteEventArgs> ItemDeleting {
  123. add { Events.AddHandler (ItemDeletingEvent, value); }
  124. remove { Events.RemoveHandler (ItemDeletingEvent, value); }
  125. }
  126. [CategoryAttribute ("Action")]
  127. public event EventHandler <ListViewEditEventArgs> ItemEditing {
  128. add { Events.AddHandler (ItemEditingEvent, value); }
  129. remove { Events.RemoveHandler (ItemEditingEvent, value); }
  130. }
  131. [CategoryAttribute ("Action")]
  132. public event EventHandler <ListViewInsertedEventArgs> ItemInserted {
  133. add { Events.AddHandler (ItemInsertedEvent, value); }
  134. remove { Events.RemoveHandler (ItemInsertedEvent, value); }
  135. }
  136. [CategoryAttribute ("Action")]
  137. public event EventHandler <ListViewInsertEventArgs> ItemInserting {
  138. add { Events.AddHandler (ItemInsertingEvent, value); }
  139. remove { Events.RemoveHandler (ItemInsertingEvent, value); }
  140. }
  141. [CategoryAttribute ("Action")]
  142. public event EventHandler <ListViewUpdatedEventArgs> ItemUpdated {
  143. add { Events.AddHandler (ItemUpdatedEvent, value); }
  144. remove { Events.RemoveHandler (ItemUpdatedEvent, value); }
  145. }
  146. [CategoryAttribute ("Action")]
  147. public event EventHandler <ListViewUpdateEventArgs> ItemUpdating {
  148. add { Events.AddHandler (ItemUpdatingEvent, value); }
  149. remove { Events.RemoveHandler (ItemUpdatingEvent, value); }
  150. }
  151. [CategoryAttribute ("Behavior")]
  152. public event EventHandler LayoutCreated {
  153. add { Events.AddHandler (LayoutCreatedEvent, value); }
  154. remove { Events.RemoveHandler (LayoutCreatedEvent, value); }
  155. }
  156. [CategoryAttribute ("Behavior")]
  157. public event EventHandler PagePropertiesChanged {
  158. add { Events.AddHandler (PagePropertiesChangedEvent, value); }
  159. remove { Events.RemoveHandler (PagePropertiesChangedEvent, value); }
  160. }
  161. [CategoryAttribute ("Behavior")]
  162. public event EventHandler <PagePropertiesChangingEventArgs> PagePropertiesChanging {
  163. add { Events.AddHandler (PagePropertiesChangingEvent, value); }
  164. remove { Events.RemoveHandler (PagePropertiesChangingEvent, value); }
  165. }
  166. [CategoryAttribute ("Action")]
  167. public event EventHandler SelectedIndexChanged {
  168. add { Events.AddHandler (SelectedIndexChangedEvent, value); }
  169. remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
  170. }
  171. [CategoryAttribute ("Action")]
  172. public event EventHandler <ListViewSelectEventArgs> SelectedIndexChanging {
  173. add { Events.AddHandler (SelectedIndexChangingEvent, value); }
  174. remove { Events.RemoveHandler (SelectedIndexChangingEvent, value); }
  175. }
  176. [CategoryAttribute ("Action")]
  177. public event EventHandler Sorted {
  178. add { Events.AddHandler (SortedEvent, value); }
  179. remove { Events.RemoveHandler (SortedEvent, value); }
  180. }
  181. [CategoryAttribute ("Action")]
  182. public event EventHandler <ListViewSortEventArgs> Sorting {
  183. add { Events.AddHandler (SortingEvent, value); }
  184. remove { Events.RemoveHandler (SortingEvent, value); }
  185. }
  186. event EventHandler <PageEventArgs> IPageableItemContainer.TotalRowCountAvailable {
  187. add { Events.AddHandler (TotalRowCountAvailableEvent, value); }
  188. remove { Events.RemoveHandler (TotalRowCountAvailableEvent, value); }
  189. }
  190. #endregion
  191. #region Properties
  192. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  193. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  194. [BrowsableAttribute (false)]
  195. public override string AccessKey {
  196. get { return base.AccessKey; }
  197. set { throw StylingNotSupported (); }
  198. }
  199. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  200. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  201. [DefaultValue (null)]
  202. [BrowsableAttribute (false)]
  203. public virtual ITemplate AlternatingItemTemplate {
  204. get { return _alternatingItemTemplate; }
  205. set { _alternatingItemTemplate = value; }
  206. }
  207. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  208. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  209. [BrowsableAttribute (false)]
  210. public override Color BackColor {
  211. get { return base.BackColor; }
  212. set { throw StylingNotSupported (); }
  213. }
  214. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  215. [BrowsableAttribute (false)]
  216. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  217. public override Color BorderColor {
  218. get { return base.BorderColor; }
  219. set { throw StylingNotSupported (); }
  220. }
  221. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  222. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  223. [BrowsableAttribute (false)]
  224. public override BorderStyle BorderStyle {
  225. get { return base.BorderStyle; }
  226. set { throw StylingNotSupported (); }
  227. }
  228. [BrowsableAttribute (false)]
  229. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  230. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  231. public override Unit BorderWidth {
  232. get { return base.BorderWidth; }
  233. set { throw StylingNotSupported (); }
  234. }
  235. public override ControlCollection Controls {
  236. get {
  237. EnsureChildControls ();
  238. return base.Controls;
  239. }
  240. }
  241. [CategoryAttribute ("Behavior")]
  242. [DefaultValue (true)]
  243. public virtual bool ConvertEmptyStringToNull {
  244. get {
  245. object o = ViewState ["ConvertEmptyStringToNull"];
  246. if (o != null)
  247. return (bool) o;
  248. return true;
  249. }
  250. set { ViewState ["ConvertEmptyStringToNull"] = value; }
  251. }
  252. public override string CssClass {
  253. get { return base.CssClass; }
  254. set { throw StylingNotSupported (); }
  255. }
  256. [DefaultValue (null)]
  257. [TypeConverterAttribute (typeof (StringArrayConverter))]
  258. [CategoryAttribute ("Data")]
  259. public virtual string [] DataKeyNames {
  260. get {
  261. if (_dataKeyNames != null)
  262. return _dataKeyNames;
  263. return new string [0];
  264. }
  265. set {
  266. if (value == null)
  267. _dataKeyNames = null;
  268. else
  269. _dataKeyNames = (string []) value.Clone ();
  270. // They will eventually be recreated while creating the child controls
  271. _dataKeyArray = null;
  272. _dataKeys = null;
  273. if (Initialized)
  274. RequiresDataBinding = true;
  275. }
  276. }
  277. [BrowsableAttribute (false)]
  278. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  279. public virtual DataKeyArray DataKeys {
  280. get {
  281. if (_dataKeys == null) {
  282. _dataKeys = new DataKeyArray (DataKeyArray);
  283. if (IsTrackingViewState)
  284. ((IStateManager) _dataKeys).TrackViewState ();
  285. }
  286. return _dataKeys;
  287. }
  288. }
  289. ArrayList DataKeyArray {
  290. get {
  291. if (_dataKeyArray == null)
  292. _dataKeyArray = new ArrayList ();
  293. return _dataKeyArray;
  294. }
  295. }
  296. [DefaultValue (-1)]
  297. [CategoryAttribute ("Misc")]
  298. public virtual int EditIndex {
  299. get { return _editIndex; }
  300. set {
  301. if (value < -1)
  302. throw new ArgumentOutOfRangeException ("value");
  303. if (value != _editIndex) {
  304. _editIndex = value;
  305. if (Initialized)
  306. RequiresDataBinding = true;
  307. }
  308. }
  309. }
  310. [BrowsableAttribute (false)]
  311. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  312. public virtual ListViewItem EditItem {
  313. get { throw new NotImplementedException (); }
  314. }
  315. [DefaultValue (null)]
  316. [BrowsableAttribute (false)]
  317. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  318. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  319. public virtual ITemplate EditItemTemplate {
  320. get { return _editItemTemplate; }
  321. set { _editItemTemplate = value; }
  322. }
  323. [DefaultValue (null)]
  324. [TemplateContainerAttribute (typeof (ListView))]
  325. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  326. [BrowsableAttribute (false)]
  327. public virtual ITemplate EmptyDataTemplate {
  328. get { return _emptyDataTemplate; }
  329. set { _emptyDataTemplate = value; }
  330. }
  331. [TemplateContainerAttribute (typeof (ListViewItem))]
  332. [DefaultValue (null)]
  333. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  334. [BrowsableAttribute (false)]
  335. public virtual ITemplate EmptyItemTemplate {
  336. get { return _emptyItemTemplate; }
  337. set { _emptyItemTemplate = value; }
  338. }
  339. [BrowsableAttribute (false)]
  340. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  341. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  342. public override FontInfo Font {
  343. get { throw StylingNotSupported (); }
  344. }
  345. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  346. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  347. [BrowsableAttribute (false)]
  348. public override Color ForeColor {
  349. get { return base.ForeColor; }
  350. set { throw StylingNotSupported (); }
  351. }
  352. [CategoryAttribute ("Misc")]
  353. [DefaultValue (1)]
  354. public virtual int GroupItemCount {
  355. get { return _groupItemCount; }
  356. set {
  357. if (value < 1)
  358. throw new ArgumentOutOfRangeException ("value");
  359. if (value != _groupItemCount) {
  360. _groupItemCount = value;
  361. if (Initialized)
  362. RequiresDataBinding = true;
  363. }
  364. }
  365. }
  366. [CategoryAttribute ("Behavior")]
  367. [DefaultValue ("groupPlaceholder")]
  368. public virtual string GroupPlaceholderID {
  369. get {
  370. string s = ViewState ["GroupPlaceholderID"] as string;
  371. if (s != null)
  372. return s;
  373. return "groupPlaceHolder";
  374. }
  375. set {
  376. if (String.IsNullOrEmpty (value))
  377. throw new ArgumentOutOfRangeException ("value");
  378. ViewState ["GroupPlaceholderID"] = value;
  379. }
  380. }
  381. [BrowsableAttribute (false)]
  382. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  383. [DefaultValue (null)]
  384. [TemplateContainerAttribute (typeof (ListViewItem))]
  385. public virtual ITemplate GroupSeparatorTemplate {
  386. get { return _groupSeparatorTemplate; }
  387. set { _groupSeparatorTemplate = value; }
  388. }
  389. [TemplateContainerAttribute (typeof (ListViewItem))]
  390. [DefaultValue (null)]
  391. [BrowsableAttribute (false)]
  392. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  393. public virtual ITemplate GroupTemplate {
  394. get { return _groupTemplate; }
  395. set { _groupTemplate = value; }
  396. }
  397. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  398. [BrowsableAttribute (false)]
  399. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  400. public override Unit Height {
  401. get { return base.Height; }
  402. set { throw StylingNotSupported (); }
  403. }
  404. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  405. [BrowsableAttribute (false)]
  406. public virtual ListViewItem InsertItem {
  407. get;
  408. private set;
  409. }
  410. [CategoryAttribute ("Misc")]
  411. [DefaultValue (InsertItemPosition.None)]
  412. public virtual InsertItemPosition InsertItemPosition {
  413. get;
  414. set;
  415. }
  416. [TemplateContainerAttribute (typeof (ListViewItem), BindingDirection.TwoWay)]
  417. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  418. [DefaultValue (null)]
  419. [BrowsableAttribute (false)]
  420. public virtual ITemplate InsertItemTemplate {
  421. get { return _insertItemTemplate; }
  422. set { _insertItemTemplate = value; }
  423. }
  424. [DefaultValue ("itemPlaceholder")]
  425. [CategoryAttribute ("Behavior")]
  426. public virtual string ItemPlaceholderID {
  427. get {
  428. string s = ViewState ["ItemPlaceHolderID"] as string;
  429. if (s != null)
  430. return s;
  431. return "itemPlaceholder";
  432. }
  433. set {
  434. if (String.IsNullOrEmpty (value))
  435. throw new ArgumentOutOfRangeException ("value");
  436. ViewState ["ItemPlaceHolderID"] = value;
  437. }
  438. }
  439. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  440. [BrowsableAttribute (false)]
  441. public virtual IList <ListViewDataItem> Items {
  442. get { throw new NotImplementedException (); }
  443. }
  444. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  445. [BrowsableAttribute (false)]
  446. [TemplateContainerAttribute (typeof (ListViewItem))]
  447. [DefaultValue (null)]
  448. public virtual ITemplate ItemSeparatorTemplate {
  449. get { return _itemSeparatorTemplate; }
  450. set { _itemSeparatorTemplate = value; }
  451. }
  452. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  453. [DefaultValue (null)]
  454. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  455. [BrowsableAttribute (false)]
  456. public virtual ITemplate ItemTemplate {
  457. get { return _itemTemplate; }
  458. set { _itemTemplate = value; }
  459. }
  460. [TemplateContainerAttribute (typeof (ListView))]
  461. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  462. [DefaultValue (null)]
  463. [BrowsableAttribute (false)]
  464. public virtual ITemplate LayoutTemplate {
  465. get { return _layoutTemplate; }
  466. set { _layoutTemplate = value; }
  467. }
  468. protected virtual int MaximumRows {
  469. get { return _maximumRows; }
  470. }
  471. [BrowsableAttribute (false)]
  472. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  473. public virtual DataKey SelectedDataKey {
  474. get {
  475. if (_dataKeyNames == null || _dataKeyNames.Length == 0)
  476. throw new InvalidOperationException ("No data keys are specified in the DataKeyNames property.");
  477. DataKeyArray dataKeys = DataKeys;
  478. int selIndex = SelectedIndex;
  479. if (selIndex > -1 || selIndex < dataKeys.Count)
  480. return dataKeys [selIndex];
  481. return null;
  482. }
  483. }
  484. [CategoryAttribute ("Misc")]
  485. [DefaultValue (-1)]
  486. public virtual int SelectedIndex {
  487. get { return _selectedIndex; }
  488. set {
  489. if (value < -1)
  490. throw new ArgumentOutOfRangeException ("value");
  491. if (value != _selectedIndex) {
  492. _selectedIndex = value;
  493. if (Initialized)
  494. RequiresDataBinding = true;
  495. }
  496. }
  497. }
  498. [BrowsableAttribute (false)]
  499. [DefaultValue (null)]
  500. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  501. [TemplateContainerAttribute (typeof (ListViewDataItem), BindingDirection.TwoWay)]
  502. public virtual ITemplate SelectedItemTemplate {
  503. get { return _selectedItemTemplate; }
  504. set { _selectedItemTemplate = value; }
  505. }
  506. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  507. [BrowsableAttribute (false)]
  508. public object SelectedValue {
  509. get {
  510. DataKey dk = SelectedDataKey;
  511. if (dk != null)
  512. return dk.Value;
  513. return null;
  514. }
  515. }
  516. [DefaultValue (SortDirection.Ascending)]
  517. [BrowsableAttribute (false)]
  518. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  519. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  520. public virtual SortDirection SortDirection {
  521. get { return _sortDirection; }
  522. }
  523. [BrowsableAttribute (false)]
  524. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  525. public virtual string SortExpression {
  526. get { return _sortExpression; }
  527. }
  528. protected virtual int StartRowIndex {
  529. get { return _startRowIndex; }
  530. }
  531. int IPageableItemContainer.MaximumRows {
  532. get { return _maximumRows; }
  533. }
  534. int IPageableItemContainer.StartRowIndex {
  535. get { return _startRowIndex; }
  536. }
  537. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  538. [BrowsableAttribute (false)]
  539. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  540. public override short TabIndex {
  541. get { return 0; }
  542. set { throw new NotSupportedException ("ListView does not allow setting this property."); }
  543. }
  544. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  545. [BrowsableAttribute (false)]
  546. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  547. public override string ToolTip {
  548. get { return base.ToolTip; }
  549. set { throw StylingNotSupported (); }
  550. }
  551. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  552. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  553. [BrowsableAttribute (false)]
  554. public override Unit Width {
  555. get { return base.Width; }
  556. set { throw StylingNotSupported (); }
  557. }
  558. #endregion
  559. public ListView ()
  560. {
  561. InsertItemPosition = InsertItemPosition.None;
  562. }
  563. protected virtual void AddControlToContainer (Control control, Control container, int addLocation)
  564. {
  565. if (control == null || container == null)
  566. return;
  567. Control ctl;
  568. if (container is HtmlTable) {
  569. ctl = new ListViewTableRow ();
  570. ctl.Controls.Add (control);
  571. } else
  572. ctl = control;
  573. container.Controls.AddAt (addLocation, ctl);
  574. }
  575. protected internal override void CreateChildControls ()
  576. {
  577. if (RequiresDataBinding)
  578. EnsureDataBound ();
  579. base.CreateChildControls ();
  580. }
  581. protected virtual int CreateChildControls (IEnumerable dataSource, bool dataBinding)
  582. {
  583. IList <ListViewDataItem> retList = null;
  584. EnsureLayoutTemplate ();
  585. RemoveItems ();
  586. bool haveDataToDisplay = _maximumRows > 0 && _startRowIndex > 0;
  587. var pagedDataSource = new ListViewPagedDataSource ();
  588. if (dataBinding) {
  589. DataSourceView view = GetData ();
  590. if (view == null)
  591. throw new InvalidOperationException ("dataSource returned a null reference for DataSourceView.");
  592. int totalRowCount = 0;
  593. if (haveDataToDisplay) {
  594. if (view.CanRetrieveTotalRowCount)
  595. totalRowCount = SelectArguments.TotalRowCount;
  596. else {
  597. ICollection ds = dataSource as ICollection;
  598. if (ds == null)
  599. throw new InvalidOperationException ("dataSource does not implement the ICollection interface.");
  600. totalRowCount = ds.Count + _startRowIndex;
  601. }
  602. }
  603. pagedDataSource.StartRowIndex = _startRowIndex;
  604. pagedDataSource.DataSource = dataSource;
  605. pagedDataSource.TotalRowCount = totalRowCount;
  606. } else {
  607. if (!(dataSource is ICollection))
  608. throw new InvalidOperationException ("dataSource does not implement the ICollection interface and dataBinding is false.");
  609. }
  610. if (GroupItemCount <= 0)
  611. retList = CreateItemsWithoutGroups (pagedDataSource, dataBinding, InsertItemPosition, DataKeyArray);
  612. if (retList == null)
  613. return 0;
  614. return retList.Count;
  615. }
  616. protected override Style CreateControlStyle ()
  617. {
  618. throw StylingNotSupported ();
  619. }
  620. protected virtual ListViewDataItem CreateDataItem (int dataItemIndex, int displayIndex)
  621. {
  622. return new ListViewDataItem (dataItemIndex, displayIndex);
  623. }
  624. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  625. {
  626. DataSourceSelectArguments arg = DataSourceSelectArguments.Empty;
  627. DataSourceView view = GetData();
  628. if (view.CanPage) {
  629. arg.StartRowIndex = _startRowIndex;
  630. if (view.CanRetrieveTotalRowCount) {
  631. arg.RetrieveTotalRowCount = true;
  632. arg.MaximumRows = _maximumRows;
  633. } else
  634. arg.MaximumRows = -1;
  635. }
  636. if (IsBoundUsingDataSourceID && !String.IsNullOrEmpty (_sortExpression)) {
  637. if (_sortDirection == SortDirection.Ascending)
  638. arg.SortExpression = _sortExpression;
  639. else
  640. arg.SortExpression = _sortExpression + " DESC";
  641. }
  642. return arg;
  643. }
  644. protected virtual void CreateEmptyDataItem ()
  645. {
  646. if (_emptyDataTemplate != null) {
  647. ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
  648. InstantiateEmptyDataTemplate (item);
  649. OnItemCreated (new ListViewItemEventArgs (item));
  650. AddControlToContainer (item, this, 0);
  651. }
  652. }
  653. protected virtual ListViewItem CreateEmptyItem ()
  654. {
  655. if (_emptyDataTemplate != null) {
  656. ListViewItem item = CreateItem (ListViewItemType.EmptyItem);
  657. InstantiateEmptyItemTemplate (item);
  658. OnItemCreated (new ListViewItemEventArgs (item));
  659. return item;
  660. }
  661. return null;
  662. }
  663. protected virtual ListViewItem CreateInsertItem ()
  664. {
  665. ListViewItem ret = CreateItem (ListViewItemType.InsertItem);
  666. InsertItem = ret;
  667. return ret;
  668. }
  669. protected virtual ListViewItem CreateItem (ListViewItemType itemType)
  670. {
  671. return new ListViewItem (itemType);
  672. }
  673. protected virtual IList <ListViewDataItem> CreateItemsInGroups (ListViewPagedDataSource dataSource, bool dataBinding, InsertItemPosition insertPosition,
  674. ArrayList keyArray)
  675. {
  676. if (_groupTemplate == null)
  677. return null;
  678. throw new NotImplementedException ();
  679. }
  680. protected virtual IList <ListViewDataItem> CreateItemsWithoutGroups (ListViewPagedDataSource dataSource, bool dataBinding,
  681. InsertItemPosition insertPosition, ArrayList keyArray)
  682. {
  683. _nonGroupedItemsContainer = FindPlaceholder (ItemPlaceholderID, _layoutTemplatePlaceholder);
  684. _nonGroupedItemsContainerItemCount = 0;
  685. if (_nonGroupedItemsContainer == null)
  686. throw new InvalidOperationException (
  687. 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));
  688. Control parent = _nonGroupedItemsContainer.Parent;
  689. int ipos = 0;
  690. if (parent != null) {
  691. ipos = parent.Controls.IndexOf (_nonGroupedItemsContainer);
  692. parent.Controls.Remove (_nonGroupedItemsContainer);
  693. _nonGroupedItemsContainer = parent;
  694. if (_nonGroupedItemsContainer != _layoutTemplatePlaceholder)
  695. AddControlToContainer (_nonGroupedItemsContainer, _layoutTemplatePlaceholder, 0);
  696. }
  697. _nonGroupedItemsContainerFirstItemIndex = ipos;
  698. List <ListViewDataItem> ret = new List <ListViewDataItem> ();
  699. ListViewItem lvi;
  700. ListViewItem container;
  701. bool needSeparator = false;
  702. if (insertPosition == InsertItemPosition.FirstItem) {
  703. lvi = CreateInsertItem ();
  704. InstantiateInsertItemTemplate (lvi);
  705. AddControlToContainer (lvi, _nonGroupedItemsContainer, ipos++);
  706. _nonGroupedItemsContainerItemCount++;
  707. needSeparator = true;
  708. }
  709. bool haveSeparatorTemplate = _itemSeparatorTemplate != null;
  710. int displayIndex = 0;
  711. ListViewDataItem lvdi;
  712. int startIndex = dataSource.StartRowIndex;
  713. foreach (object item in dataSource) {
  714. if (needSeparator && haveSeparatorTemplate) {
  715. container = new ListViewItem ();
  716. InstantiateItemSeparatorTemplate (container);
  717. AddControlToContainer (container, _nonGroupedItemsContainer, ipos++);
  718. _nonGroupedItemsContainerItemCount++;
  719. }
  720. lvdi = CreateDataItem (startIndex + displayIndex, displayIndex);
  721. InstantiateItemTemplate (lvdi, displayIndex);
  722. if (dataBinding) {
  723. lvdi.DataItem = item;
  724. OrderedDictionary dict = new OrderedDictionary ();
  725. string[] dataKeyNames = DataKeyNames;
  726. foreach (string s in dataKeyNames)
  727. dict.Add (s, DataBinder.GetPropertyValue (item, s));
  728. DataKey dk = new DataKey (dict, dataKeyNames);
  729. if (keyArray.Count == displayIndex)
  730. keyArray.Add (dk);
  731. else
  732. keyArray [displayIndex] = dk;
  733. }
  734. OnItemCreated (new ListViewItemEventArgs (lvdi));
  735. AddControlToContainer (lvdi, _nonGroupedItemsContainer, ipos++);
  736. _nonGroupedItemsContainerItemCount++;
  737. if (!needSeparator)
  738. needSeparator = true;
  739. if (dataBinding) {
  740. lvdi.DataBind ();
  741. OnItemDataBound (new ListViewItemEventArgs (lvdi));
  742. }
  743. displayIndex++;
  744. ret.Add (lvdi);
  745. }
  746. if (insertPosition == InsertItemPosition.LastItem) {
  747. if (needSeparator && haveSeparatorTemplate) {
  748. container = new ListViewItem ();
  749. InstantiateItemSeparatorTemplate (container);
  750. AddControlToContainer (container, _nonGroupedItemsContainer, ipos++);
  751. _nonGroupedItemsContainerItemCount++;
  752. }
  753. lvi = CreateInsertItem ();
  754. InstantiateInsertItemTemplate (lvi);
  755. AddControlToContainer (lvi, _nonGroupedItemsContainer, ipos++);
  756. _nonGroupedItemsContainerItemCount++;
  757. }
  758. return ret;
  759. }
  760. protected virtual void CreateLayoutTemplate ()
  761. {
  762. if (_layoutTemplate != null) {
  763. _layoutTemplatePlaceholder = new Control ();
  764. _layoutTemplate.InstantiateIn (_layoutTemplatePlaceholder);
  765. AddControlToContainer (_layoutTemplatePlaceholder, this, 0);
  766. }
  767. OnLayoutCreated (EventArgs.Empty);
  768. }
  769. public virtual void DeleteItem (int itemIndex)
  770. {
  771. }
  772. protected virtual void EnsureLayoutTemplate ()
  773. {
  774. Controls.Clear ();
  775. CreateLayoutTemplate ();
  776. }
  777. public virtual void ExtractItemValues (IOrderedDictionary itemValues, ListViewItem item, bool includePrimaryKey)
  778. {
  779. if (itemValues == null)
  780. throw new ArgumentNullException ("itemValues");
  781. if (!(item is ListViewDataItem))
  782. throw new InvalidOperationException ("item is not a ListViewDataItem object.");
  783. }
  784. protected virtual Control FindPlaceholder (string containerID, Control container)
  785. {
  786. if (container == null || String.IsNullOrEmpty (containerID))
  787. return null;
  788. return container.FindControl (containerID);
  789. }
  790. public virtual void InsertNewItem (bool causesValidation)
  791. {
  792. ListViewItem insertItem = InsertItem;
  793. if (insertItem == null)
  794. throw new InvalidOperationException ("The ListView control does not have an insert item.");
  795. DataSourceView dsv = null;
  796. ListViewInsertEventArgs eventArgs = null;
  797. if (IsBoundUsingDataSourceID) {
  798. dsv = GetData ();
  799. if (dsv == null)
  800. throw new InvalidOperationException ("Missing data.");
  801. eventArgs = new ListViewInsertEventArgs (insertItem);
  802. ExtractItemValues (eventArgs.Values, insertItem, true);
  803. } else
  804. eventArgs = new ListViewInsertEventArgs (insertItem);
  805. OnItemInserting (eventArgs);
  806. if (!eventArgs.Cancel && IsBoundUsingDataSourceID) {
  807. _lastInsertValues = eventArgs.Values;
  808. dsv.Insert (_lastInsertValues, new DataSourceViewOperationCallback (InsertNewItemCallback));
  809. }
  810. }
  811. bool InsertNewItemCallback (int recordsAffected, Exception ex)
  812. {
  813. var eventArgs = new ListViewInsertedEventArgs (_lastInsertValues, recordsAffected, ex);
  814. OnItemInserted (eventArgs);
  815. _lastInsertValues = null;
  816. if (ex != null && !eventArgs.ExceptionHandled)
  817. return false;
  818. // This will effectively reset the insert values
  819. if (!eventArgs.KeepInInsertMode)
  820. RequiresDataBinding = true;
  821. return true;
  822. }
  823. protected virtual void InstantiateEmptyDataTemplate (Control container)
  824. {
  825. if (_emptyDataTemplate != null)
  826. _emptyDataTemplate.InstantiateIn (container);
  827. }
  828. protected virtual void InstantiateEmptyItemTemplate (Control container)
  829. {
  830. if (_emptyItemTemplate != null)
  831. _emptyItemTemplate.InstantiateIn (container);
  832. }
  833. protected virtual void InstantiateGroupSeparatorTemplate (Control container)
  834. {
  835. if (_groupSeparatorTemplate != null)
  836. _groupSeparatorTemplate.InstantiateIn (container);
  837. }
  838. protected virtual void InstantiateGroupTemplate (Control container)
  839. {
  840. if (_groupTemplate != null)
  841. _groupTemplate.InstantiateIn (container);
  842. }
  843. protected virtual void InstantiateInsertItemTemplate (Control container)
  844. {
  845. if (_insertItemTemplate != null)
  846. _insertItemTemplate.InstantiateIn (container);
  847. }
  848. protected virtual void InstantiateItemSeparatorTemplate (Control container)
  849. {
  850. if (_itemSeparatorTemplate != null)
  851. _itemSeparatorTemplate.InstantiateIn (container);
  852. }
  853. protected virtual void InstantiateItemTemplate (Control container, int displayIndex)
  854. {
  855. if (_itemTemplate == null)
  856. throw new InvalidOperationException ("ItemTemplate is missing");
  857. ITemplate template = _itemTemplate;
  858. if ((displayIndex % 2 != 0) && _alternatingItemTemplate != null)
  859. template = _alternatingItemTemplate;
  860. if ((displayIndex == _selectedIndex) && _selectedItemTemplate != null)
  861. template = _selectedItemTemplate;
  862. if ((displayIndex == _editIndex) && _editItemTemplate != null)
  863. template = _editItemTemplate;
  864. template.InstantiateIn (container);
  865. }
  866. void LoadDataKeysState (object savedState)
  867. {
  868. object[] state = savedState as object[];
  869. int len = state != null ? state.Length : 0;
  870. if (len == 0)
  871. return;
  872. ArrayList dataKeyArray = DataKeyArray;
  873. DataKey dk;
  874. string[] keyNames = DataKeyNames;
  875. for (int i = 0; i < len; i++) {
  876. dk = new DataKey (new OrderedDictionary (), keyNames);
  877. ((IStateManager)dk).LoadViewState (state [i]);
  878. dataKeyArray.Add (dk);
  879. }
  880. _dataKeys = null;
  881. }
  882. protected override void LoadControlState (object savedState)
  883. {
  884. object[] state = savedState as object[];
  885. if (state == null || state.Length != 8)
  886. return;
  887. object o;
  888. base.LoadViewState (state [0]);
  889. if ((o = state [1]) != null)
  890. DataKeyNames = (string[])o;
  891. LoadDataKeysState (state [2]);
  892. if ((o = state [3]) != null)
  893. GroupItemCount = (int)o;
  894. if ((o = state [4]) != null)
  895. EditIndex = (int)o;
  896. if ((o = state [5]) != null)
  897. SelectedIndex = (int)o;
  898. if ((o = state [6]) != null)
  899. _sortDirection = (SortDirection)o;
  900. if ((o = state [7]) != null)
  901. _sortExpression = (string)o;
  902. }
  903. protected override void LoadViewState (object savedState)
  904. {
  905. object[] state = savedState as object[];
  906. int len = state != null ? state.Length : 0;
  907. if (len == 0)
  908. return;
  909. base.LoadViewState (state [0]);
  910. }
  911. protected override bool OnBubbleEvent (object source, EventArgs e)
  912. {
  913. ListViewCommandEventArgs args = e as ListViewCommandEventArgs;
  914. if (args != null) {
  915. bool causesValidation = false;
  916. IButtonControl button = args.CommandSource as IButtonControl;
  917. if (button != null && button.CausesValidation) {
  918. Page.Validate (button.ValidationGroup);
  919. causesValidation = true;
  920. }
  921. ProcessCommand (args, causesValidation);
  922. return true;
  923. }
  924. return base.OnBubbleEvent (source, e);
  925. }
  926. void ProcessCommand (ListViewCommandEventArgs args, bool causesValidation)
  927. {
  928. OnItemCommand (args);
  929. }
  930. protected override void OnInit (EventArgs e)
  931. {
  932. Page.RegisterRequiresControlState (this);
  933. base.OnInit (e);
  934. }
  935. void InvokeEvent <T> (object key, T args) where T : EventArgs
  936. {
  937. EventHandlerList events = Events;
  938. if (events != null) {
  939. EventHandler <T> eh = events [key] as EventHandler <T>;
  940. if (eh != null)
  941. eh (this, args);
  942. }
  943. }
  944. void InvokeEvent (object key, EventArgs args)
  945. {
  946. EventHandlerList events = Events;
  947. if (events != null) {
  948. EventHandler eh = events [key] as EventHandler;
  949. if (eh != null)
  950. eh (this, args);
  951. }
  952. }
  953. protected virtual void OnItemCanceling (ListViewCancelEventArgs e)
  954. {
  955. InvokeEvent <ListViewCancelEventArgs> (ItemCancellingEvent, e);
  956. }
  957. protected virtual void OnItemCommand (ListViewCommandEventArgs e)
  958. {
  959. InvokeEvent <ListViewCommandEventArgs> (ItemCommandEvent, e);
  960. }
  961. protected virtual void OnItemCreated (ListViewItemEventArgs e)
  962. {
  963. InvokeEvent <ListViewItemEventArgs> (ItemCreatedEvent, e);
  964. }
  965. protected virtual void OnItemDataBound (ListViewItemEventArgs e)
  966. {
  967. InvokeEvent <ListViewItemEventArgs> (ItemDataBoundEvent, e);
  968. }
  969. protected virtual void OnItemDeleted (ListViewDeletedEventArgs e)
  970. {
  971. InvokeEvent <ListViewDeletedEventArgs> (ItemDeletedEvent, e);
  972. }
  973. protected virtual void OnItemDeleting (ListViewDeleteEventArgs e)
  974. {
  975. InvokeEvent <ListViewDeleteEventArgs> (ItemDeletingEvent, e);
  976. }
  977. protected virtual void OnItemEditing (ListViewEditEventArgs e)
  978. {
  979. InvokeEvent <ListViewEditEventArgs> (ItemEditingEvent, e);
  980. }
  981. protected virtual void OnItemInserted (ListViewInsertedEventArgs e)
  982. {
  983. InvokeEvent <ListViewInsertedEventArgs> (ItemInsertedEvent, e);
  984. }
  985. protected virtual void OnItemInserting (ListViewInsertEventArgs e)
  986. {
  987. InvokeEvent <ListViewInsertEventArgs> (ItemInsertingEvent, e);
  988. }
  989. protected virtual void OnItemUpdated (ListViewUpdatedEventArgs e)
  990. {
  991. InvokeEvent <ListViewUpdatedEventArgs> (ItemUpdatedEvent, e);
  992. }
  993. protected virtual void OnItemUpdating (ListViewUpdateEventArgs e)
  994. {
  995. InvokeEvent <ListViewUpdateEventArgs> (ItemUpdatingEvent, e);
  996. }
  997. protected virtual void OnLayoutCreated (EventArgs e)
  998. {
  999. InvokeEvent (LayoutCreatedEvent, e);
  1000. }
  1001. protected virtual void OnPagePropertiesChanged (EventArgs e)
  1002. {
  1003. InvokeEvent (PagePropertiesChangedEvent, e);
  1004. }
  1005. protected virtual void OnPagePropertiesChanging (PagePropertiesChangingEventArgs e)
  1006. {
  1007. InvokeEvent (PagePropertiesChangingEvent, e);
  1008. }
  1009. protected virtual void OnSelectedIndexChanged (EventArgs e)
  1010. {
  1011. InvokeEvent (SelectedIndexChangedEvent, e);
  1012. }
  1013. protected virtual void OnSelectedIndexChanging (ListViewSelectEventArgs e)
  1014. {
  1015. InvokeEvent (SelectedIndexChangingEvent, e);
  1016. }
  1017. protected virtual void OnSorted (EventArgs e)
  1018. {
  1019. InvokeEvent (SortedEvent, e);
  1020. }
  1021. protected virtual void OnSorting (ListViewSortEventArgs e)
  1022. {
  1023. InvokeEvent <ListViewSortEventArgs> (SortingEvent, e);
  1024. }
  1025. protected virtual void OnTotalRowCountAvailable (PageEventArgs e)
  1026. {
  1027. InvokeEvent <PageEventArgs> (TotalRowCountAvailableEvent, e);
  1028. }
  1029. protected override void PerformDataBinding (IEnumerable data)
  1030. {
  1031. base.PerformDataBinding (data);
  1032. TrackViewState ();
  1033. int childCount = CreateChildControls (data, true);
  1034. ChildControlsCreated = true;
  1035. }
  1036. protected override void PerformSelect ()
  1037. {
  1038. EnsureLayoutTemplate ();
  1039. base.PerformSelect ();
  1040. }
  1041. protected virtual void RemoveItems ()
  1042. {
  1043. if (_nonGroupedItemsContainer != null)
  1044. RemoveItems (_nonGroupedItemsContainer, _nonGroupedItemsContainerFirstItemIndex, _nonGroupedItemsContainerItemCount);
  1045. }
  1046. void RemoveItems (Control container, int start, int count)
  1047. {
  1048. int i = count;
  1049. while (i-- > 0)
  1050. container.Controls.RemoveAt (start);
  1051. }
  1052. protected override void Render (HtmlTextWriter writer)
  1053. {
  1054. base.Render (writer);
  1055. // Why override?
  1056. }
  1057. object SaveDataKeysState ()
  1058. {
  1059. DataKeyArray dka = DataKeys;
  1060. int len = dka != null ? dka.Count : 0;
  1061. if (len == 0)
  1062. return null;
  1063. object[] state = new object [len];
  1064. DataKey dk;
  1065. for (int i = 0; i < len; i++) {
  1066. dk = dka [i];
  1067. if (dk == null) {
  1068. state [i] = null;
  1069. continue;
  1070. }
  1071. state [i] = ((IStateManager)dk).SaveViewState ();
  1072. }
  1073. return state;
  1074. }
  1075. protected override object SaveControlState ()
  1076. {
  1077. object[] ret = new object [8];
  1078. string[] dataKeyNames = DataKeyNames;
  1079. object dataKeysState = SaveDataKeysState ();
  1080. ret [0] = base.SaveViewState ();
  1081. ret [1] = dataKeyNames.Length > 0 ? dataKeyNames : null;
  1082. ret [2] = dataKeysState != null ? dataKeysState : null;
  1083. ret [3] = _groupItemCount > 1 ? (object)_groupItemCount : null;
  1084. ret [4] = _editIndex != -1 ? (object)_editIndex : null;
  1085. ret [5] = _selectedIndex != -1 ? (object)_selectedIndex : null;
  1086. ret [6] = _sortDirection != SortDirection.Ascending ? (object)_sortDirection : null;
  1087. ret [7] = String.IsNullOrEmpty (_sortExpression) ? null : _sortExpression;
  1088. return ret;
  1089. }
  1090. protected override object SaveViewState ()
  1091. {
  1092. object[] states = new object [2];
  1093. states [0] = base.SaveViewState ();
  1094. states [1] = null; // What goes here?
  1095. return states;
  1096. }
  1097. protected virtual void SetPageProperties (int startRowIndex, int maximumRows, bool databind)
  1098. {
  1099. }
  1100. public virtual void Sort (string sortExpression, SortDirection sortDirection)
  1101. {
  1102. }
  1103. void IPageableItemContainer.SetPageProperties (int startRowIndex, int maximumRows, bool databind)
  1104. {
  1105. throw new NotImplementedException ();
  1106. }
  1107. public virtual void UpdateItem (int itemIndex, bool causesValidation)
  1108. {
  1109. }
  1110. NotSupportedException StylingNotSupported ()
  1111. {
  1112. return new NotSupportedException ("Style properties are not supported on ListView. Apply styling or CSS classes to the elements in the ListView's templates.");
  1113. }
  1114. }
  1115. }
  1116. #endif