DetailsView.cs 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  1. //
  2. // System.Web.UI.WebControls.DetailsView.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Collections;
  31. using System.Collections.Specialized;
  32. using System.ComponentModel;
  33. using System.Web.UI;
  34. using System.Security.Permissions;
  35. using System.Text;
  36. using System.IO;
  37. using System.Reflection;
  38. namespace System.Web.UI.WebControls
  39. {
  40. [SupportsEventValidation]
  41. [ToolboxDataAttribute ("<{0}:DetailsView runat=\"server\" Width=\"125px\" Height=\"50px\"></{0}:DetailsView>")]
  42. [DesignerAttribute ("System.Web.UI.Design.WebControls.DetailsViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  43. [ControlValuePropertyAttribute ("SelectedValue")]
  44. [DefaultEventAttribute ("PageIndexChanging")]
  45. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  46. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  47. public class DetailsView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IDataItemContainer, INamingContainer, IPostBackEventHandler, IPostBackContainer
  48. {
  49. object dataItem;
  50. Table table;
  51. DetailsViewRowCollection rows;
  52. DetailsViewRow headerRow;
  53. DetailsViewRow footerRow;
  54. DetailsViewRow bottomPagerRow;
  55. DetailsViewRow topPagerRow;
  56. IOrderedDictionary currentEditRowKeys;
  57. IOrderedDictionary currentEditNewValues;
  58. IOrderedDictionary currentEditOldValues;
  59. ITemplate pagerTemplate;
  60. ITemplate emptyDataTemplate;
  61. ITemplate headerTemplate;
  62. ITemplate footerTemplate;
  63. PropertyDescriptor[] cachedKeyProperties;
  64. readonly string[] emptyKeys = new string[0];
  65. CommandField commandField;
  66. DetailsViewRow commandRow;
  67. // View state
  68. DataControlFieldCollection columns;
  69. PagerSettings pagerSettings;
  70. TableItemStyle alternatingRowStyle;
  71. TableItemStyle editRowStyle;
  72. TableItemStyle insertRowStyle;
  73. TableItemStyle emptyDataRowStyle;
  74. TableItemStyle footerStyle;
  75. TableItemStyle headerStyle;
  76. TableItemStyle pagerStyle;
  77. TableItemStyle rowStyle;
  78. TableItemStyle commandRowStyle;
  79. TableItemStyle fieldHeaderStyle;
  80. DataKey key;
  81. DataKey oldEditValues;
  82. AutoGeneratedFieldProperties[] autoFieldProperties;
  83. private static readonly object PageIndexChangedEvent = new object();
  84. private static readonly object PageIndexChangingEvent = new object();
  85. private static readonly object ItemCommandEvent = new object();
  86. private static readonly object ItemCreatedEvent = new object();
  87. private static readonly object ItemDeletedEvent = new object();
  88. private static readonly object ItemDeletingEvent = new object();
  89. private static readonly object ItemInsertedEvent = new object();
  90. private static readonly object ItemInsertingEvent = new object();
  91. private static readonly object ModeChangingEvent = new object();
  92. private static readonly object ModeChangedEvent = new object();
  93. private static readonly object ItemUpdatedEvent = new object();
  94. private static readonly object ItemUpdatingEvent = new object();
  95. // Control state
  96. int pageIndex;
  97. DetailsViewMode currentMode = DetailsViewMode.ReadOnly;
  98. int pageCount = 0;
  99. public DetailsView ()
  100. {
  101. rows = new DetailsViewRowCollection (new ArrayList ());
  102. }
  103. public event EventHandler PageIndexChanged {
  104. add { Events.AddHandler (PageIndexChangedEvent, value); }
  105. remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
  106. }
  107. public event DetailsViewPageEventHandler PageIndexChanging {
  108. add { Events.AddHandler (PageIndexChangingEvent, value); }
  109. remove { Events.RemoveHandler (PageIndexChangingEvent, value); }
  110. }
  111. public event DetailsViewCommandEventHandler ItemCommand {
  112. add { Events.AddHandler (ItemCommandEvent, value); }
  113. remove { Events.RemoveHandler (ItemCommandEvent, value); }
  114. }
  115. public event EventHandler ItemCreated {
  116. add { Events.AddHandler (ItemCreatedEvent, value); }
  117. remove { Events.RemoveHandler (ItemCreatedEvent, value); }
  118. }
  119. public event DetailsViewDeletedEventHandler ItemDeleted {
  120. add { Events.AddHandler (ItemDeletedEvent, value); }
  121. remove { Events.RemoveHandler (ItemDeletedEvent, value); }
  122. }
  123. public event DetailsViewDeleteEventHandler ItemDeleting {
  124. add { Events.AddHandler (ItemDeletingEvent, value); }
  125. remove { Events.RemoveHandler (ItemDeletingEvent, value); }
  126. }
  127. public event DetailsViewInsertedEventHandler ItemInserted {
  128. add { Events.AddHandler (ItemInsertedEvent, value); }
  129. remove { Events.RemoveHandler (ItemInsertedEvent, value); }
  130. }
  131. public event DetailsViewInsertEventHandler ItemInserting {
  132. add { Events.AddHandler (ItemInsertingEvent, value); }
  133. remove { Events.RemoveHandler (ItemInsertingEvent, value); }
  134. }
  135. public event DetailsViewModeEventHandler ModeChanging {
  136. add { Events.AddHandler (ModeChangingEvent, value); }
  137. remove { Events.RemoveHandler (ModeChangingEvent, value); }
  138. }
  139. public event EventHandler ModeChanged {
  140. add { Events.AddHandler (ModeChangedEvent, value); }
  141. remove { Events.RemoveHandler (ModeChangedEvent, value); }
  142. }
  143. public event DetailsViewUpdatedEventHandler ItemUpdated {
  144. add { Events.AddHandler (ItemUpdatedEvent, value); }
  145. remove { Events.RemoveHandler (ItemUpdatedEvent, value); }
  146. }
  147. public event DetailsViewUpdateEventHandler ItemUpdating {
  148. add { Events.AddHandler (ItemUpdatingEvent, value); }
  149. remove { Events.RemoveHandler (ItemUpdatingEvent, value); }
  150. }
  151. protected virtual void OnPageIndexChanged (EventArgs e)
  152. {
  153. if (Events != null) {
  154. EventHandler eh = (EventHandler) Events [PageIndexChangedEvent];
  155. if (eh != null) eh (this, e);
  156. }
  157. }
  158. protected virtual void OnPageIndexChanging (DetailsViewPageEventArgs e)
  159. {
  160. if (Events != null) {
  161. DetailsViewPageEventHandler eh = (DetailsViewPageEventHandler) Events [PageIndexChangingEvent];
  162. if (eh != null) eh (this, e);
  163. }
  164. }
  165. protected virtual void OnItemCommand (DetailsViewCommandEventArgs e)
  166. {
  167. if (Events != null) {
  168. DetailsViewCommandEventHandler eh = (DetailsViewCommandEventHandler) Events [ItemCommandEvent];
  169. if (eh != null) eh (this, e);
  170. }
  171. }
  172. protected virtual void OnItemCreated (EventArgs e)
  173. {
  174. if (Events != null) {
  175. EventHandler eh = (EventHandler) Events [ItemCreatedEvent];
  176. if (eh != null) eh (this, e);
  177. }
  178. }
  179. protected virtual void OnItemDeleted (DetailsViewDeletedEventArgs e)
  180. {
  181. if (Events != null) {
  182. DetailsViewDeletedEventHandler eh = (DetailsViewDeletedEventHandler) Events [ItemDeletedEvent];
  183. if (eh != null) eh (this, e);
  184. }
  185. }
  186. protected virtual void OnItemInserted (DetailsViewInsertedEventArgs e)
  187. {
  188. if (Events != null) {
  189. DetailsViewInsertedEventHandler eh = (DetailsViewInsertedEventHandler) Events [ItemInsertedEvent];
  190. if (eh != null) eh (this, e);
  191. }
  192. }
  193. protected virtual void OnItemInserting (DetailsViewInsertEventArgs e)
  194. {
  195. if (Events != null) {
  196. DetailsViewInsertEventHandler eh = (DetailsViewInsertEventHandler) Events [ItemInsertingEvent];
  197. if (eh != null) eh (this, e);
  198. }
  199. }
  200. protected virtual void OnItemDeleting (DetailsViewDeleteEventArgs e)
  201. {
  202. if (Events != null) {
  203. DetailsViewDeleteEventHandler eh = (DetailsViewDeleteEventHandler) Events [ItemDeletingEvent];
  204. if (eh != null) eh (this, e);
  205. }
  206. }
  207. protected virtual void OnModeChanged (EventArgs e)
  208. {
  209. if (Events != null) {
  210. EventHandler eh = (EventHandler) Events [ModeChangedEvent];
  211. if (eh != null) eh (this, e);
  212. }
  213. }
  214. protected virtual void OnModeChanging (DetailsViewModeEventArgs e)
  215. {
  216. if (Events != null) {
  217. DetailsViewModeEventHandler eh = (DetailsViewModeEventHandler) Events [ModeChangingEvent];
  218. if (eh != null) eh (this, e);
  219. }
  220. }
  221. protected virtual void OnItemUpdated (DetailsViewUpdatedEventArgs e)
  222. {
  223. if (Events != null) {
  224. DetailsViewUpdatedEventHandler eh = (DetailsViewUpdatedEventHandler) Events [ItemUpdatedEvent];
  225. if (eh != null) eh (this, e);
  226. }
  227. }
  228. protected virtual void OnItemUpdating (DetailsViewUpdateEventArgs e)
  229. {
  230. if (Events != null) {
  231. DetailsViewUpdateEventHandler eh = (DetailsViewUpdateEventHandler) Events [ItemUpdatingEvent];
  232. if (eh != null) eh (this, e);
  233. }
  234. }
  235. [WebCategoryAttribute ("Paging")]
  236. [DefaultValueAttribute (false)]
  237. public virtual bool AllowPaging {
  238. get {
  239. object ob = ViewState ["AllowPaging"];
  240. if (ob != null) return (bool) ob;
  241. return false;
  242. }
  243. set {
  244. ViewState ["AllowPaging"] = value;
  245. RequireBinding ();
  246. }
  247. }
  248. [DefaultValueAttribute (null)]
  249. [WebCategoryAttribute ("Styles")]
  250. [PersistenceMode (PersistenceMode.InnerProperty)]
  251. [NotifyParentProperty (true)]
  252. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  253. public TableItemStyle AlternatingRowStyle {
  254. get {
  255. if (alternatingRowStyle == null) {
  256. alternatingRowStyle = new TableItemStyle ();
  257. if (IsTrackingViewState)
  258. alternatingRowStyle.TrackViewState();
  259. }
  260. return alternatingRowStyle;
  261. }
  262. }
  263. [WebCategoryAttribute ("Behavior")]
  264. [DefaultValueAttribute (false)]
  265. public virtual bool AutoGenerateEditButton {
  266. get {
  267. object ob = ViewState ["AutoGenerateEditButton"];
  268. if (ob != null) return (bool) ob;
  269. return false;
  270. }
  271. set {
  272. ViewState ["AutoGenerateEditButton"] = value;
  273. RequireBinding ();
  274. }
  275. }
  276. [WebCategoryAttribute ("Behavior")]
  277. [DefaultValueAttribute (false)]
  278. public virtual bool AutoGenerateDeleteButton {
  279. get {
  280. object ob = ViewState ["AutoGenerateDeleteButton"];
  281. if (ob != null) return (bool) ob;
  282. return false;
  283. }
  284. set {
  285. ViewState ["AutoGenerateDeleteButton"] = value;
  286. RequireBinding ();
  287. }
  288. }
  289. [WebCategoryAttribute ("Behavior")]
  290. [DefaultValueAttribute (false)]
  291. public virtual bool AutoGenerateInsertButton {
  292. get {
  293. object ob = ViewState ["AutoGenerateInsertButton"];
  294. if (ob != null) return (bool) ob;
  295. return false;
  296. }
  297. set {
  298. ViewState ["AutoGenerateInsertButton"] = value;
  299. RequireBinding ();
  300. }
  301. }
  302. [WebCategoryAttribute ("Behavior")]
  303. [DefaultValueAttribute (true)]
  304. public virtual bool AutoGenerateRows {
  305. get {
  306. object ob = ViewState ["AutoGenerateRows"];
  307. if (ob != null) return (bool) ob;
  308. return true;
  309. }
  310. set {
  311. ViewState ["AutoGenerateRows"] = value;
  312. RequireBinding ();
  313. }
  314. }
  315. [UrlPropertyAttribute]
  316. [WebCategoryAttribute ("Appearance")]
  317. [DefaultValueAttribute ("")]
  318. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  319. public virtual string BackImageUrl {
  320. get {
  321. object ob = ViewState ["BackImageUrl"];
  322. if (ob != null) return (string) ob;
  323. return string.Empty;
  324. }
  325. set {
  326. ViewState ["BackImageUrl"] = value;
  327. RequireBinding ();
  328. }
  329. }
  330. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  331. [BrowsableAttribute (false)]
  332. public virtual DetailsViewRow BottomPagerRow {
  333. get {
  334. EnsureDataBound ();
  335. return bottomPagerRow;
  336. }
  337. }
  338. [WebCategoryAttribute ("Accessibility")]
  339. [DefaultValueAttribute ("")]
  340. [LocalizableAttribute (true)]
  341. public virtual string Caption {
  342. get {
  343. object ob = ViewState ["Caption"];
  344. if (ob != null) return (string) ob;
  345. return string.Empty;
  346. }
  347. set {
  348. ViewState ["Caption"] = value;
  349. RequireBinding ();
  350. }
  351. }
  352. [WebCategoryAttribute ("Accessibility")]
  353. [DefaultValueAttribute (TableCaptionAlign.NotSet)]
  354. public virtual TableCaptionAlign CaptionAlign
  355. {
  356. get {
  357. object o = ViewState ["CaptionAlign"];
  358. if(o != null) return (TableCaptionAlign) o;
  359. return TableCaptionAlign.NotSet;
  360. }
  361. set {
  362. ViewState ["CaptionAlign"] = value;
  363. RequireBinding ();
  364. }
  365. }
  366. [WebCategoryAttribute ("Layout")]
  367. [DefaultValueAttribute (-1)]
  368. public virtual int CellPadding
  369. {
  370. get {
  371. object o = ViewState ["CellPadding"];
  372. if (o != null) return (int) o;
  373. return -1;
  374. }
  375. set {
  376. if (value < -1)
  377. throw new ArgumentOutOfRangeException ("< -1");
  378. ViewState["CellPadding"] = value;
  379. RequireBinding ();
  380. }
  381. }
  382. [WebCategoryAttribute ("Layout")]
  383. [DefaultValueAttribute (0)]
  384. public virtual int CellSpacing
  385. {
  386. get {
  387. object o = ViewState ["CellSpacing"];
  388. if (o != null) return (int) o;
  389. return 0;
  390. }
  391. set {
  392. if (value < -1)
  393. throw new ArgumentOutOfRangeException ("< -1");
  394. ViewState ["CellSpacing"] = value;
  395. RequireBinding ();
  396. }
  397. }
  398. [DefaultValueAttribute (null)]
  399. [WebCategoryAttribute ("Styles")]
  400. [PersistenceMode (PersistenceMode.InnerProperty)]
  401. [NotifyParentProperty (true)]
  402. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  403. public TableItemStyle CommandRowStyle {
  404. get {
  405. if (commandRowStyle == null) {
  406. commandRowStyle = new TableItemStyle ();
  407. if (IsTrackingViewState)
  408. commandRowStyle.TrackViewState();
  409. }
  410. return commandRowStyle;
  411. }
  412. }
  413. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  414. [BrowsableAttribute (false)]
  415. public DetailsViewMode CurrentMode {
  416. get {
  417. return currentMode;
  418. }
  419. }
  420. [DefaultValueAttribute (DetailsViewMode.ReadOnly)]
  421. [WebCategoryAttribute ("Behavior")]
  422. public virtual DetailsViewMode DefaultMode {
  423. get {
  424. object o = ViewState ["DefaultMode"];
  425. if (o != null) return (DetailsViewMode) o;
  426. return DetailsViewMode.ReadOnly;
  427. }
  428. set {
  429. ViewState ["DefaultMode"] = value;
  430. RequireBinding ();
  431. }
  432. }
  433. [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  434. [MergablePropertyAttribute (false)]
  435. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  436. [DefaultValueAttribute (null)]
  437. [WebCategoryAttribute ("Misc")]
  438. public virtual DataControlFieldCollection Fields {
  439. get {
  440. if (columns == null) {
  441. columns = new DataControlFieldCollection ();
  442. columns.FieldsChanged += new EventHandler (OnFieldsChanged);
  443. if (IsTrackingViewState)
  444. ((IStateManager)columns).TrackViewState ();
  445. }
  446. return columns;
  447. }
  448. }
  449. [DefaultValueAttribute (null)]
  450. [WebCategoryAttribute ("Data")]
  451. [TypeConverter (typeof(StringArrayConverter))]
  452. [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  453. public virtual string[] DataKeyNames
  454. {
  455. get {
  456. object o = ViewState ["DataKeyNames"];
  457. if (o != null) return (string[]) o;
  458. return emptyKeys;
  459. }
  460. set {
  461. ViewState ["DataKeyNames"] = value;
  462. RequireBinding ();
  463. }
  464. }
  465. [BrowsableAttribute (false)]
  466. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  467. public virtual DataKey DataKey {
  468. get {
  469. EnsureDataBound ();
  470. return key;
  471. }
  472. }
  473. [WebCategoryAttribute ("Styles")]
  474. [PersistenceMode (PersistenceMode.InnerProperty)]
  475. [NotifyParentProperty (true)]
  476. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  477. [DefaultValueAttribute (null)]
  478. public TableItemStyle EditRowStyle {
  479. get {
  480. if (editRowStyle == null) {
  481. editRowStyle = new TableItemStyle ();
  482. if (IsTrackingViewState)
  483. editRowStyle.TrackViewState();
  484. }
  485. return editRowStyle;
  486. }
  487. }
  488. [WebCategoryAttribute ("Styles")]
  489. [PersistenceMode (PersistenceMode.InnerProperty)]
  490. [NotifyParentProperty (true)]
  491. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  492. [DefaultValueAttribute (null)]
  493. public TableItemStyle EmptyDataRowStyle {
  494. get {
  495. if (emptyDataRowStyle == null) {
  496. emptyDataRowStyle = new TableItemStyle ();
  497. if (IsTrackingViewState)
  498. emptyDataRowStyle.TrackViewState();
  499. }
  500. return emptyDataRowStyle;
  501. }
  502. }
  503. [DefaultValue (null)]
  504. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  505. [PersistenceMode (PersistenceMode.InnerProperty)]
  506. [Browsable (false)]
  507. public virtual ITemplate EmptyDataTemplate {
  508. get { return emptyDataTemplate; }
  509. set { emptyDataTemplate = value; RequireBinding (); }
  510. }
  511. [LocalizableAttribute (true)]
  512. [WebCategoryAttribute ("Appearance")]
  513. [DefaultValueAttribute ("")]
  514. public virtual string EmptyDataText {
  515. get {
  516. object ob = ViewState ["EmptyDataText"];
  517. if (ob != null) return (string) ob;
  518. return string.Empty;
  519. }
  520. set {
  521. ViewState ["EmptyDataText"] = value;
  522. RequireBinding ();
  523. }
  524. }
  525. [WebCategoryAttribute ("Behavior")]
  526. [DefaultValueAttribute (false)]
  527. public virtual bool EnablePagingCallbacks {
  528. get {
  529. object ob = ViewState ["EnablePagingCallbacks"];
  530. if (ob != null) return (bool) ob;
  531. return false;
  532. }
  533. set {
  534. ViewState ["EnablePagingCallbacks"] = value;
  535. RequireBinding ();
  536. }
  537. }
  538. [WebCategoryAttribute ("Styles")]
  539. [PersistenceMode (PersistenceMode.InnerProperty)]
  540. [NotifyParentProperty (true)]
  541. [DefaultValue (null)]
  542. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  543. public TableItemStyle FieldHeaderStyle {
  544. get {
  545. if (fieldHeaderStyle == null) {
  546. fieldHeaderStyle = new TableItemStyle ();
  547. if (IsTrackingViewState)
  548. fieldHeaderStyle.TrackViewState();
  549. }
  550. return fieldHeaderStyle;
  551. }
  552. }
  553. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  554. [BrowsableAttribute (false)]
  555. public virtual DetailsViewRow FooterRow {
  556. get {
  557. EnsureChildControls ();
  558. return footerRow;
  559. }
  560. }
  561. [DefaultValue (null)]
  562. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  563. [PersistenceMode (PersistenceMode.InnerProperty)]
  564. [Browsable (false)]
  565. public virtual ITemplate FooterTemplate {
  566. get { return footerTemplate; }
  567. set { footerTemplate = value; RequireBinding (); }
  568. }
  569. [LocalizableAttribute (true)]
  570. [WebCategoryAttribute ("Appearance")]
  571. [DefaultValueAttribute ("")]
  572. public virtual string FooterText {
  573. get {
  574. object ob = ViewState ["FooterText"];
  575. if (ob != null) return (string) ob;
  576. return string.Empty;
  577. }
  578. set {
  579. ViewState ["FooterText"] = value;
  580. RequireBinding ();
  581. }
  582. }
  583. [WebCategoryAttribute ("Styles")]
  584. [PersistenceMode (PersistenceMode.InnerProperty)]
  585. [NotifyParentProperty (true)]
  586. [DefaultValue (null)]
  587. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  588. public TableItemStyle FooterStyle {
  589. get {
  590. if (footerStyle == null) {
  591. footerStyle = new TableItemStyle ();
  592. if (IsTrackingViewState)
  593. footerStyle.TrackViewState();
  594. }
  595. return footerStyle;
  596. }
  597. }
  598. [WebCategoryAttribute ("Appearance")]
  599. [DefaultValueAttribute (GridLines.Both)]
  600. public virtual GridLines GridLines {
  601. get {
  602. object ob = ViewState ["GridLines"];
  603. if (ob != null) return (GridLines) ob;
  604. return GridLines.Both;
  605. }
  606. set {
  607. ViewState ["GridLines"] = value;
  608. }
  609. }
  610. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  611. [BrowsableAttribute (false)]
  612. public virtual DetailsViewRow HeaderRow {
  613. get {
  614. EnsureChildControls ();
  615. return headerRow;
  616. }
  617. }
  618. [WebCategoryAttribute ("Styles")]
  619. [PersistenceMode (PersistenceMode.InnerProperty)]
  620. [NotifyParentProperty (true)]
  621. [DefaultValue (null)]
  622. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  623. public TableItemStyle HeaderStyle {
  624. get {
  625. if (headerStyle == null) {
  626. headerStyle = new TableItemStyle ();
  627. if (IsTrackingViewState)
  628. headerStyle.TrackViewState();
  629. }
  630. return headerStyle;
  631. }
  632. }
  633. [DefaultValue (null)]
  634. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  635. [PersistenceMode (PersistenceMode.InnerProperty)]
  636. [Browsable (false)]
  637. public virtual ITemplate HeaderTemplate {
  638. get { return headerTemplate; }
  639. set { headerTemplate = value; RequireBinding (); }
  640. }
  641. [LocalizableAttribute (true)]
  642. [WebCategoryAttribute ("Appearance")]
  643. [DefaultValueAttribute ("")]
  644. public virtual string HeaderText {
  645. get {
  646. object ob = ViewState ["HeaderText"];
  647. if (ob != null) return (string) ob;
  648. return string.Empty;
  649. }
  650. set {
  651. ViewState ["HeaderText"] = value;
  652. RequireBinding ();
  653. }
  654. }
  655. [Category ("Layout")]
  656. [DefaultValueAttribute (HorizontalAlign.NotSet)]
  657. public virtual HorizontalAlign HorizontalAlign {
  658. get {
  659. object ob = ViewState ["HorizontalAlign"];
  660. if (ob != null) return (HorizontalAlign) ob;
  661. return HorizontalAlign.NotSet;
  662. }
  663. set {
  664. ViewState ["HorizontalAlign"] = value;
  665. RequireBinding ();
  666. }
  667. }
  668. [WebCategoryAttribute ("Styles")]
  669. [PersistenceMode (PersistenceMode.InnerProperty)]
  670. [NotifyParentProperty (true)]
  671. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  672. [DefaultValueAttribute (null)]
  673. public TableItemStyle InsertRowStyle {
  674. get {
  675. if (insertRowStyle == null) {
  676. insertRowStyle = new TableItemStyle ();
  677. if (IsTrackingViewState)
  678. insertRowStyle.TrackViewState();
  679. }
  680. return insertRowStyle;
  681. }
  682. }
  683. [BrowsableAttribute (false)]
  684. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  685. public virtual int PageCount {
  686. get {
  687. if (pageCount != 0) return pageCount;
  688. EnsureDataBound ();
  689. return pageCount;
  690. }
  691. }
  692. [WebCategoryAttribute ("Paging")]
  693. [BindableAttribute (true, BindingDirection.OneWay)]
  694. [DefaultValueAttribute (0)]
  695. public virtual int PageIndex {
  696. get {
  697. return pageIndex;
  698. }
  699. set {
  700. pageIndex = value;
  701. RequireBinding ();
  702. }
  703. }
  704. [WebCategoryAttribute ("Paging")]
  705. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  706. [NotifyParentPropertyAttribute (true)]
  707. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  708. public virtual PagerSettings PagerSettings {
  709. get {
  710. if (pagerSettings == null) {
  711. pagerSettings = new PagerSettings (this);
  712. if (IsTrackingViewState)
  713. ((IStateManager)pagerSettings).TrackViewState ();
  714. }
  715. return pagerSettings;
  716. }
  717. }
  718. [WebCategoryAttribute ("Styles")]
  719. [PersistenceMode (PersistenceMode.InnerProperty)]
  720. [NotifyParentProperty (true)]
  721. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  722. public TableItemStyle PagerStyle {
  723. get {
  724. if (pagerStyle == null) {
  725. pagerStyle = new TableItemStyle ();
  726. if (IsTrackingViewState)
  727. pagerStyle.TrackViewState();
  728. }
  729. return pagerStyle;
  730. }
  731. }
  732. [DefaultValue (null)]
  733. /* DataControlPagerCell isnt specified in the docs */
  734. //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
  735. [PersistenceMode (PersistenceMode.InnerProperty)]
  736. [Browsable (false)]
  737. public virtual ITemplate PagerTemplate {
  738. get { return pagerTemplate; }
  739. set { pagerTemplate = value; RequireBinding (); }
  740. }
  741. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  742. [BrowsableAttribute (false)]
  743. public virtual DetailsViewRowCollection Rows {
  744. get {
  745. EnsureChildControls ();
  746. return rows;
  747. }
  748. }
  749. [WebCategoryAttribute ("Styles")]
  750. [PersistenceMode (PersistenceMode.InnerProperty)]
  751. [NotifyParentProperty (true)]
  752. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  753. [DefaultValue (null)]
  754. public TableItemStyle RowStyle {
  755. get {
  756. if (rowStyle == null) {
  757. rowStyle = new TableItemStyle ();
  758. if (IsTrackingViewState)
  759. rowStyle.TrackViewState();
  760. }
  761. return rowStyle;
  762. }
  763. }
  764. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  765. [BrowsableAttribute (false)]
  766. public object SelectedValue {
  767. get { return DataKey.Value; }
  768. }
  769. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  770. [BrowsableAttribute (false)]
  771. public virtual DetailsViewRow TopPagerRow {
  772. get {
  773. EnsureDataBound ();
  774. return topPagerRow;
  775. }
  776. }
  777. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  778. [BrowsableAttribute (false)]
  779. public virtual object DataItem {
  780. get {
  781. EnsureDataBound ();
  782. return dataItem;
  783. }
  784. }
  785. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  786. [BrowsableAttribute (false)]
  787. public int DataItemCount {
  788. get { return PageCount; }
  789. }
  790. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  791. [BrowsableAttribute (false)]
  792. public virtual int DataItemIndex {
  793. get { return PageIndex; }
  794. }
  795. int IDataItemContainer.DisplayIndex {
  796. get { return PageIndex; }
  797. }
  798. public virtual bool IsBindableType (Type type)
  799. {
  800. return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Guid);
  801. }
  802. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  803. {
  804. return base.CreateDataSourceSelectArguments ();
  805. }
  806. protected virtual ICollection CreateFieldSet (object dataItem, bool useDataSource)
  807. {
  808. ArrayList fields = new ArrayList ();
  809. if (AutoGenerateRows) {
  810. if (useDataSource) {
  811. if (dataItem != null)
  812. fields.AddRange (CreateAutoGeneratedRows (dataItem));
  813. } else {
  814. if (autoFieldProperties != null) {
  815. foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
  816. fields.Add (CreateAutoGeneratedRow (props));
  817. }
  818. }
  819. }
  820. fields.AddRange (Fields);
  821. if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateInsertButton) {
  822. CommandField field = new CommandField ();
  823. field.ShowEditButton = AutoGenerateEditButton;
  824. field.ShowDeleteButton = AutoGenerateDeleteButton;
  825. field.ShowInsertButton = AutoGenerateInsertButton;
  826. fields.Add (field);
  827. commandField = field;
  828. }
  829. return fields;
  830. }
  831. protected virtual ICollection CreateAutoGeneratedRows (object dataItem)
  832. {
  833. ArrayList list = new ArrayList ();
  834. autoFieldProperties = CreateAutoFieldProperties (dataItem);
  835. foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
  836. list.Add (CreateAutoGeneratedRow (props));
  837. return list;
  838. }
  839. protected virtual AutoGeneratedField CreateAutoGeneratedRow (AutoGeneratedFieldProperties fieldProperties)
  840. {
  841. return new AutoGeneratedField (fieldProperties);
  842. }
  843. AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
  844. {
  845. PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
  846. ArrayList retVal = new ArrayList();
  847. if (props != null && props.Count > 0)
  848. {
  849. foreach (PropertyDescriptor current in props) {
  850. if (IsBindableType (current.PropertyType)) {
  851. AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
  852. ((IStateManager)field).TrackViewState();
  853. field.Name = current.Name;
  854. field.DataField = current.Name;
  855. field.IsReadOnly = current.IsReadOnly;
  856. field.Type = current.PropertyType;
  857. retVal.Add (field);
  858. }
  859. }
  860. }
  861. if (retVal.Count > 0)
  862. return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
  863. else
  864. return new AutoGeneratedFieldProperties [0];
  865. }
  866. protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
  867. {
  868. DetailsViewRow row;
  869. if (rowType == DataControlRowType.Pager)
  870. row = new DetailsViewPagerRow (rowIndex, rowType, rowState);
  871. else
  872. row = new DetailsViewRow (rowIndex, rowType, rowState);
  873. OnItemCreated (EventArgs.Empty);
  874. return row;
  875. }
  876. void RequireBinding ()
  877. {
  878. if (Initialized) {
  879. RequiresDataBinding = true;
  880. pageCount = 0;
  881. }
  882. }
  883. protected virtual Table CreateTable ()
  884. {
  885. Table table = new Table ();
  886. table.Caption = Caption;
  887. table.CaptionAlign = CaptionAlign;
  888. table.CellPadding = CellPadding;
  889. table.CellSpacing = CellSpacing;
  890. table.HorizontalAlign = HorizontalAlign;
  891. table.BackImageUrl = BackImageUrl;
  892. return table;
  893. }
  894. [MonoTODO]
  895. protected override Style CreateControlStyle ()
  896. {
  897. return base.CreateControlStyle ();
  898. }
  899. protected override int CreateChildControls (IEnumerable data, bool dataBinding)
  900. {
  901. PagedDataSource dataSource;
  902. if (dataBinding) {
  903. DataSourceView view = GetData ();
  904. dataSource = new PagedDataSource ();
  905. dataSource.DataSource = data;
  906. if (AllowPaging) {
  907. dataSource.AllowPaging = true;
  908. dataSource.PageSize = 1;
  909. dataSource.CurrentPageIndex = PageIndex;
  910. if (view.CanPage) {
  911. dataSource.AllowServerPaging = true;
  912. if (view.CanRetrieveTotalRowCount)
  913. dataSource.VirtualCount = SelectArguments.TotalRowCount;
  914. }
  915. }
  916. pageCount = dataSource.PageCount;
  917. }
  918. else
  919. {
  920. dataSource = new PagedDataSource ();
  921. dataSource.DataSource = data;
  922. if (AllowPaging) {
  923. dataSource.AllowPaging = true;
  924. dataSource.PageSize = 1;
  925. dataSource.CurrentPageIndex = PageIndex;
  926. }
  927. }
  928. bool showPager = AllowPaging && (PageCount > 1);
  929. Controls.Clear ();
  930. table = CreateTable ();
  931. Controls.Add (table);
  932. ArrayList list = new ArrayList ();
  933. if (Page == null || !Page.IsPostBack)
  934. currentMode = DefaultMode;
  935. // Gets the current data item
  936. IEnumerator e = dataSource.GetEnumerator ();
  937. if (e.MoveNext ())
  938. dataItem = e.Current;
  939. else
  940. dataItem = null;
  941. // Creates the set of fields to show
  942. ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding);
  943. DataControlField[] fields = new DataControlField [fieldCollection.Count];
  944. fieldCollection.CopyTo (fields, 0);
  945. foreach (DataControlField field in fields) {
  946. field.Initialize (false, this);
  947. if (EnablePagingCallbacks)
  948. field.ValidateSupportsCallback ();
  949. }
  950. // Main table creation
  951. headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
  952. DataControlFieldCell headerCell = new DataControlFieldCell (null);
  953. headerCell.ColumnSpan = 2;
  954. if (headerTemplate != null)
  955. headerTemplate.InstantiateIn (headerCell);
  956. else
  957. headerCell.Text = HeaderText;
  958. headerRow.Cells.Add (headerCell);
  959. table.Rows.Add (headerRow);
  960. if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
  961. topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
  962. InitializePager (topPagerRow, dataSource);
  963. table.Rows.Add (topPagerRow);
  964. }
  965. if (dataSource.Count > 0) {
  966. foreach (DataControlField field in fields) {
  967. DataControlRowState rstate = GetRowState (list.Count);
  968. DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate);
  969. InitializeRow (row, field);
  970. table.Rows.Add (row);
  971. list.Add (row);
  972. if (commandField == field)
  973. commandRow = row;
  974. }
  975. if (!dataBinding) {
  976. if (CurrentMode == DetailsViewMode.Edit)
  977. oldEditValues = new DataKey (new OrderedDictionary ());
  978. key = new DataKey (new OrderedDictionary (), DataKeyNames);
  979. }
  980. } else {
  981. table.Rows.Add (CreateEmptyrRow ());
  982. }
  983. rows = new DetailsViewRowCollection (list);
  984. if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
  985. bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
  986. InitializePager (bottomPagerRow, dataSource);
  987. table.Rows.Add (bottomPagerRow);
  988. }
  989. footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal);
  990. DataControlFieldCell footerCell = new DataControlFieldCell (null);
  991. footerCell.ColumnSpan = 2;
  992. if (footerTemplate != null)
  993. footerTemplate.InstantiateIn (footerCell);
  994. else
  995. footerCell.Text = FooterText;
  996. footerRow.Cells.Add (footerCell);
  997. table.Rows.Add (footerRow);
  998. if (dataBinding)
  999. DataBind (false);
  1000. return dataSource.DataSourceCount;
  1001. }
  1002. [MonoTODO]
  1003. protected override void EnsureDataBound ()
  1004. {
  1005. base.EnsureDataBound ();
  1006. }
  1007. DataControlRowState GetRowState (int index)
  1008. {
  1009. DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
  1010. if (CurrentMode == DetailsViewMode.Edit) rstate |= DataControlRowState.Edit;
  1011. else if (CurrentMode == DetailsViewMode.Insert) rstate |= DataControlRowState.Insert;
  1012. return rstate;
  1013. }
  1014. protected virtual void InitializePager (DetailsViewRow row, PagedDataSource dataSource)
  1015. {
  1016. TableCell cell = new TableCell ();
  1017. cell.ColumnSpan = 2;
  1018. if (pagerTemplate != null)
  1019. pagerTemplate.InstantiateIn (cell);
  1020. else
  1021. cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
  1022. row.Cells.Add (cell);
  1023. }
  1024. DetailsViewRow CreateEmptyrRow ()
  1025. {
  1026. DetailsViewRow row = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
  1027. TableCell cell = new TableCell ();
  1028. cell.ColumnSpan = 2;
  1029. if (emptyDataTemplate != null)
  1030. emptyDataTemplate.InstantiateIn (cell);
  1031. else
  1032. cell.Text = EmptyDataText;
  1033. row.Cells.Add (cell);
  1034. return row;
  1035. }
  1036. protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
  1037. {
  1038. DataControlFieldCell cell;
  1039. if (field.ShowHeader) {
  1040. cell = new DataControlFieldCell (field);
  1041. row.Cells.Add (cell);
  1042. field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
  1043. }
  1044. cell = new DataControlFieldCell (field);
  1045. if (!field.ShowHeader)
  1046. cell.ColumnSpan = 2;
  1047. row.Cells.Add (cell);
  1048. field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);
  1049. }
  1050. IOrderedDictionary CreateRowDataKey (object dataItem)
  1051. {
  1052. if (cachedKeyProperties == null) {
  1053. PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
  1054. cachedKeyProperties = new PropertyDescriptor [DataKeyNames.Length];
  1055. for (int n=0; n<DataKeyNames.Length; n++) {
  1056. PropertyDescriptor p = props [DataKeyNames[n]];
  1057. if (p == null)
  1058. new InvalidOperationException ("Property '" + DataKeyNames[n] + "' not found in object of type " + dataItem.GetType());
  1059. cachedKeyProperties [n] = p;
  1060. }
  1061. }
  1062. OrderedDictionary dic = new OrderedDictionary ();
  1063. foreach (PropertyDescriptor p in cachedKeyProperties)
  1064. dic [p.Name] = p.GetValue (dataItem);
  1065. return dic;
  1066. }
  1067. IOrderedDictionary GetRowValues (bool includeReadOnlyFields, bool includePrimaryKey)
  1068. {
  1069. OrderedDictionary dic = new OrderedDictionary ();
  1070. ExtractRowValues (dic, includeReadOnlyFields, includePrimaryKey);
  1071. return dic;
  1072. }
  1073. protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, bool includeReadOnlyFields, bool includePrimaryKey)
  1074. {
  1075. foreach (DetailsViewRow row in Rows) {
  1076. if (row.Cells.Count < 1) continue;
  1077. DataControlFieldCell c = row.Cells[row.Cells.Count-1] as DataControlFieldCell;
  1078. if (c != null)
  1079. c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
  1080. }
  1081. if (!includePrimaryKey && DataKeyNames != null)
  1082. foreach (string key in DataKeyNames)
  1083. fieldValues.Remove (key);
  1084. }
  1085. protected override HtmlTextWriterTag TagKey {
  1086. get {
  1087. if (EnablePagingCallbacks)
  1088. return HtmlTextWriterTag.Div;
  1089. else
  1090. return HtmlTextWriterTag.Table;
  1091. }
  1092. }
  1093. public sealed override void DataBind ()
  1094. {
  1095. DataSourceView view = GetData ();
  1096. if (AllowPaging && view.CanPage) {
  1097. SelectArguments.StartRowIndex = PageIndex;
  1098. SelectArguments.MaximumRows = 1;
  1099. if (view.CanRetrieveTotalRowCount)
  1100. SelectArguments.RetrieveTotalRowCount = true;
  1101. }
  1102. cachedKeyProperties = null;
  1103. base.DataBind ();
  1104. if (dataItem != null) {
  1105. if (CurrentMode == DetailsViewMode.Edit)
  1106. oldEditValues = new DataKey (GetRowValues (false, true));
  1107. key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
  1108. }
  1109. }
  1110. protected internal override void PerformDataBinding (IEnumerable data)
  1111. {
  1112. base.PerformDataBinding (data);
  1113. }
  1114. [MonoTODO]
  1115. protected internal virtual void PrepareControlHierarchy ()
  1116. {
  1117. throw new NotImplementedException ();
  1118. }
  1119. protected internal override void OnInit (EventArgs e)
  1120. {
  1121. Page.RegisterRequiresControlState (this);
  1122. base.OnInit (e);
  1123. }
  1124. void OnFieldsChanged (object sender, EventArgs args)
  1125. {
  1126. RequireBinding ();
  1127. }
  1128. protected override void OnDataSourceViewChanged (object sender, EventArgs e)
  1129. {
  1130. base.OnDataSourceViewChanged (sender, e);
  1131. RequireBinding ();
  1132. }
  1133. protected override bool OnBubbleEvent (object source, EventArgs e)
  1134. {
  1135. DetailsViewCommandEventArgs args = e as DetailsViewCommandEventArgs;
  1136. if (args != null) {
  1137. OnItemCommand (args);
  1138. ProcessEvent (args.CommandName, args.CommandArgument as string);
  1139. }
  1140. return base.OnBubbleEvent (source, e);
  1141. }
  1142. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  1143. {
  1144. RaisePostBackEvent (eventArgument);
  1145. }
  1146. // TODO: This is prolly obsolete
  1147. protected virtual void RaisePostBackEvent (string eventArgument)
  1148. {
  1149. int i = eventArgument.IndexOf ('$');
  1150. if (i != -1)
  1151. ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
  1152. else
  1153. ProcessEvent (eventArgument, null);
  1154. }
  1155. void ProcessEvent (string eventName, string param)
  1156. {
  1157. switch (eventName)
  1158. {
  1159. case DataControlCommands.PageCommandName:
  1160. int newIndex = -1;
  1161. switch (param) {
  1162. case DataControlCommands.FirstPageCommandArgument:
  1163. newIndex = 0;
  1164. break;
  1165. case DataControlCommands.LastPageCommandArgument:
  1166. newIndex = PageCount - 1;
  1167. break;
  1168. case DataControlCommands.NextPageCommandArgument:
  1169. if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
  1170. break;
  1171. case DataControlCommands.PreviousPageCommandArgument:
  1172. if (PageIndex > 0) newIndex = PageIndex - 1;
  1173. break;
  1174. default:
  1175. newIndex = int.Parse (param) - 1;
  1176. break;
  1177. }
  1178. ShowPage (newIndex);
  1179. break;
  1180. case DataControlCommands.FirstPageCommandArgument:
  1181. ShowPage (0);
  1182. break;
  1183. case DataControlCommands.LastPageCommandArgument:
  1184. ShowPage (PageCount - 1);
  1185. break;
  1186. case DataControlCommands.NextPageCommandArgument:
  1187. if (PageIndex < PageCount - 1)
  1188. ShowPage (PageIndex + 1);
  1189. break;
  1190. case DataControlCommands.PreviousPageCommandArgument:
  1191. if (PageIndex > 0)
  1192. ShowPage (PageIndex - 1);
  1193. break;
  1194. case DataControlCommands.EditCommandName:
  1195. ChangeMode (DetailsViewMode.Edit);
  1196. break;
  1197. case DataControlCommands.NewCommandName:
  1198. ChangeMode (DetailsViewMode.Insert);
  1199. break;
  1200. case DataControlCommands.UpdateCommandName:
  1201. UpdateItem (param, true);
  1202. break;
  1203. case DataControlCommands.CancelCommandName:
  1204. CancelEdit ();
  1205. break;
  1206. case DataControlCommands.DeleteCommandName:
  1207. DeleteItem ();
  1208. break;
  1209. case DataControlCommands.InsertCommandName:
  1210. InsertItem (true);
  1211. break;
  1212. }
  1213. }
  1214. void ShowPage (int newIndex)
  1215. {
  1216. DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
  1217. OnPageIndexChanging (args);
  1218. if (!args.Cancel) {
  1219. EndRowEdit ();
  1220. PageIndex = args.NewPageIndex;
  1221. OnPageIndexChanged (EventArgs.Empty);
  1222. }
  1223. }
  1224. public void ChangeMode (DetailsViewMode newMode)
  1225. {
  1226. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
  1227. OnModeChanging (args);
  1228. if (!args.Cancel) {
  1229. currentMode = args.NewMode;
  1230. OnModeChanged (EventArgs.Empty);
  1231. RequireBinding ();
  1232. }
  1233. }
  1234. void CancelEdit ()
  1235. {
  1236. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
  1237. OnModeChanging (args);
  1238. if (!args.Cancel) {
  1239. EndRowEdit ();
  1240. }
  1241. }
  1242. public virtual void UpdateItem (bool causesValidation)
  1243. {
  1244. UpdateItem (null, causesValidation);
  1245. }
  1246. void UpdateItem (string param, bool causesValidation)
  1247. {
  1248. if (causesValidation)
  1249. Page.Validate ();
  1250. if (currentMode != DetailsViewMode.Edit) throw new NotSupportedException ();
  1251. currentEditOldValues = oldEditValues.Values;
  1252. currentEditRowKeys = DataKey.Values;
  1253. currentEditNewValues = GetRowValues (false, false);
  1254. DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1255. OnItemUpdating (args);
  1256. if (!args.Cancel) {
  1257. DataSourceView view = GetData ();
  1258. if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
  1259. view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
  1260. } else
  1261. EndRowEdit ();
  1262. }
  1263. bool UpdateCallback (int recordsAffected, Exception exception)
  1264. {
  1265. DetailsViewUpdatedEventArgs dargs = new DetailsViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1266. OnItemUpdated (dargs);
  1267. if (!dargs.KeepInEditMode)
  1268. EndRowEdit ();
  1269. return dargs.ExceptionHandled;
  1270. }
  1271. public virtual void InsertItem (bool causesValidation)
  1272. {
  1273. InsertItem (null, causesValidation);
  1274. }
  1275. void InsertItem (string param, bool causesValidation)
  1276. {
  1277. if (causesValidation)
  1278. Page.Validate ();
  1279. if (currentMode != DetailsViewMode.Insert) throw new NotSupportedException ();
  1280. currentEditNewValues = GetRowValues (false, true);
  1281. DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
  1282. OnItemInserting (args);
  1283. if (!args.Cancel) {
  1284. DataSourceView view = GetData ();
  1285. if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
  1286. view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
  1287. } else
  1288. EndRowEdit ();
  1289. }
  1290. bool InsertCallback (int recordsAffected, Exception exception)
  1291. {
  1292. DetailsViewInsertedEventArgs dargs = new DetailsViewInsertedEventArgs (recordsAffected, exception, currentEditNewValues);
  1293. OnItemInserted (dargs);
  1294. if (!dargs.KeepInInsertMode)
  1295. EndRowEdit ();
  1296. return dargs.ExceptionHandled;
  1297. }
  1298. public virtual void DeleteItem ()
  1299. {
  1300. currentEditRowKeys = DataKey == null ? null : DataKey.Values;
  1301. currentEditNewValues = GetRowValues (true, true);
  1302. DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
  1303. OnItemDeleting (args);
  1304. if (!args.Cancel) {
  1305. if (PageIndex == PageCount - 1)
  1306. PageIndex --;
  1307. RequireBinding ();
  1308. DataSourceView view = GetData ();
  1309. if (view != null)
  1310. view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
  1311. else {
  1312. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
  1313. OnItemDeleted (dargs);
  1314. }
  1315. }
  1316. }
  1317. bool DeleteCallback (int recordsAffected, Exception exception)
  1318. {
  1319. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
  1320. OnItemDeleted (dargs);
  1321. return dargs.ExceptionHandled;
  1322. }
  1323. void EndRowEdit ()
  1324. {
  1325. ChangeMode (DefaultMode);
  1326. oldEditValues = new DataKey (new OrderedDictionary ());
  1327. currentEditRowKeys = null;
  1328. currentEditOldValues = null;
  1329. currentEditNewValues = null;
  1330. RequireBinding ();
  1331. }
  1332. protected internal override void LoadControlState (object ob)
  1333. {
  1334. if (ob == null) return;
  1335. object[] state = (object[]) ob;
  1336. base.LoadControlState (state[0]);
  1337. pageIndex = (int) state[1];
  1338. pageCount = (int) state[2];
  1339. currentMode = (DetailsViewMode) state[3];
  1340. }
  1341. protected internal override object SaveControlState ()
  1342. {
  1343. object bstate = base.SaveControlState ();
  1344. return new object[] {
  1345. bstate, pageIndex, pageCount, currentMode
  1346. };
  1347. }
  1348. protected override void TrackViewState()
  1349. {
  1350. base.TrackViewState();
  1351. if (columns != null) ((IStateManager)columns).TrackViewState();
  1352. if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
  1353. if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
  1354. if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
  1355. if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
  1356. if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
  1357. if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
  1358. if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
  1359. if (insertRowStyle != null) ((IStateManager)insertRowStyle).TrackViewState();
  1360. if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
  1361. if (key != null) ((IStateManager)key).TrackViewState();
  1362. if (autoFieldProperties != null) {
  1363. foreach (IStateManager sm in autoFieldProperties)
  1364. sm.TrackViewState ();
  1365. }
  1366. }
  1367. protected override object SaveViewState()
  1368. {
  1369. object[] states = new object [14];
  1370. states[0] = base.SaveViewState();
  1371. states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
  1372. states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
  1373. states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
  1374. states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
  1375. states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
  1376. states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
  1377. states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
  1378. states[8] = (insertRowStyle == null ? null : ((IStateManager)insertRowStyle).SaveViewState());
  1379. states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
  1380. states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
  1381. states[11] = (key == null ? null : ((IStateManager)key).SaveViewState());
  1382. states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
  1383. if (autoFieldProperties != null) {
  1384. object[] data = new object [autoFieldProperties.Length];
  1385. bool allNull = true;
  1386. for (int n=0; n<data.Length; n++) {
  1387. data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
  1388. if (data [n] != null) allNull = false;
  1389. }
  1390. if (!allNull) states [13] = data;
  1391. }
  1392. for (int i = states.Length - 1; i >= 0; i--) {
  1393. if (states [i] != null)
  1394. return states;
  1395. }
  1396. return null;
  1397. }
  1398. protected override void LoadViewState (object savedState)
  1399. {
  1400. if (savedState == null) {
  1401. base.LoadViewState (null);
  1402. return;
  1403. }
  1404. object [] states = (object []) savedState;
  1405. if (states[13] != null) {
  1406. object[] data = (object[]) states [13];
  1407. autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
  1408. for (int n=0; n<data.Length; n++) {
  1409. IStateManager p = new AutoGeneratedFieldProperties ();
  1410. p.TrackViewState ();
  1411. p.LoadViewState (data [n]);
  1412. autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
  1413. }
  1414. }
  1415. base.LoadViewState (states[0]);
  1416. EnsureChildControls ();
  1417. if (states[1] != null) ((IStateManager)Fields).LoadViewState (states[1]);
  1418. if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
  1419. if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
  1420. if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
  1421. if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
  1422. if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
  1423. if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
  1424. if (states[8] != null) ((IStateManager)InsertRowStyle).LoadViewState (states[8]);
  1425. if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
  1426. if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
  1427. if (states[11] != null) ((IStateManager)DataKey).LoadViewState (states[11]);
  1428. if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
  1429. }
  1430. void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
  1431. {
  1432. RaiseCallbackEvent (eventArgs);
  1433. }
  1434. string callbackResult;
  1435. protected virtual void RaiseCallbackEvent (string eventArgs)
  1436. {
  1437. string[] clientData = eventArgs.Split ('|');
  1438. pageIndex = int.Parse (clientData[0]);
  1439. RequireBinding ();
  1440. RaisePostBackEvent (clientData[2]);
  1441. EnsureDataBound ();
  1442. StringWriter sw = new StringWriter ();
  1443. sw.Write (PageIndex.ToString());
  1444. HtmlTextWriter writer = new HtmlTextWriter (sw);
  1445. RenderGrid (writer);
  1446. callbackResult = sw.ToString ();
  1447. }
  1448. string ICallbackEventHandler.GetCallbackResult ()
  1449. {
  1450. return GetCallbackResult ();
  1451. }
  1452. protected virtual string GetCallbackResult ()
  1453. {
  1454. return callbackResult;
  1455. }
  1456. [MonoTODO]
  1457. protected virtual string GetCallbackScript (IButtonControl buttonControl, string argument)
  1458. {
  1459. throw new NotImplementedException ();
  1460. }
  1461. string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
  1462. {
  1463. if (EnablePagingCallbacks)
  1464. return "javascript:GridView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
  1465. else
  1466. return null;
  1467. }
  1468. [MonoTODO]
  1469. protected override void OnPagePreLoad (object sender, EventArgs e)
  1470. {
  1471. base.OnPagePreLoad (sender, e);
  1472. }
  1473. protected internal override void OnPreRender (EventArgs e)
  1474. {
  1475. base.OnPreRender (e);
  1476. if (EnablePagingCallbacks)
  1477. {
  1478. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(GridView), "GridView.js")) {
  1479. string url = Page.ClientScript.GetWebResourceUrl (typeof(GridView), "GridView.js");
  1480. Page.ClientScript.RegisterClientScriptInclude (typeof(GridView), "GridView.js", url);
  1481. }
  1482. string cgrid = ClientID + "_data";
  1483. string script = string.Format ("var {0} = new Object ();\n", cgrid);
  1484. script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
  1485. script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
  1486. Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
  1487. // Make sure the basic script infrastructure is rendered
  1488. Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
  1489. Page.ClientScript.GetPostBackClientHyperlink (this, "");
  1490. }
  1491. }
  1492. protected internal override void Render (HtmlTextWriter writer)
  1493. {
  1494. if (EnablePagingCallbacks)
  1495. base.RenderBeginTag (writer);
  1496. else
  1497. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1498. RenderGrid (writer);
  1499. if (EnablePagingCallbacks)
  1500. base.RenderEndTag (writer);
  1501. else
  1502. writer.RenderEndTag ();
  1503. }
  1504. void RenderGrid (HtmlTextWriter writer)
  1505. {
  1506. table.GridLines = GridLines;
  1507. table.ControlStyle.MergeWith (ControlStyle);
  1508. table.RenderBeginTag (writer);
  1509. foreach (DetailsViewRow row in table.Rows)
  1510. {
  1511. switch (row.RowType) {
  1512. case DataControlRowType.Header:
  1513. if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
  1514. break;
  1515. case DataControlRowType.Footer:
  1516. if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
  1517. break;
  1518. case DataControlRowType.Pager:
  1519. if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
  1520. break;
  1521. case DataControlRowType.EmptyDataRow:
  1522. if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
  1523. break;
  1524. default:
  1525. if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
  1526. break;
  1527. }
  1528. if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
  1529. alternatingRowStyle.AddAttributesToRender (writer, row);
  1530. if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
  1531. editRowStyle.AddAttributesToRender (writer, row);
  1532. if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null)
  1533. insertRowStyle.AddAttributesToRender (writer, row);
  1534. if (row == commandRow && commandRowStyle != null)
  1535. commandRowStyle.AddAttributesToRender (writer, row);
  1536. row.RenderBeginTag (writer);
  1537. for (int n=0; n<row.Cells.Count; n++) {
  1538. DataControlFieldCell fcell = row.Cells[n] as DataControlFieldCell;
  1539. if (fcell != null && fcell.ContainingField != null) {
  1540. if (n == 0 && fcell.ContainingField.ShowHeader) {
  1541. if (fieldHeaderStyle != null)
  1542. fieldHeaderStyle.AddAttributesToRender (writer, fcell);
  1543. fcell.ContainingField.HeaderStyle.AddAttributesToRender (writer, fcell);
  1544. }
  1545. else
  1546. fcell.ContainingField.ItemStyle.AddAttributesToRender (writer, fcell);
  1547. }
  1548. row.Cells[n].Render (writer);
  1549. }
  1550. row.RenderEndTag (writer);
  1551. }
  1552. table.RenderEndTag (writer);
  1553. }
  1554. [MonoTODO]
  1555. PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
  1556. {
  1557. PostBackOptions pbo = new PostBackOptions (this, control.CommandName + "$" + control.CommandArgument);
  1558. return pbo;
  1559. }
  1560. }
  1561. }
  1562. #endif