DetailsView.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  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. // View state
  66. DataControlFieldCollection columns;
  67. PagerSettings pagerSettings;
  68. TableItemStyle alternatingRowStyle;
  69. TableItemStyle editRowStyle;
  70. TableItemStyle insertRowStyle;
  71. TableItemStyle emptyDataRowStyle;
  72. TableItemStyle footerStyle;
  73. TableItemStyle headerStyle;
  74. TableItemStyle pagerStyle;
  75. TableItemStyle rowStyle;
  76. TableItemStyle commandRowStyle;
  77. TableItemStyle fieldHeaderStyle;
  78. DataKey key;
  79. DataKey oldEditValues;
  80. AutoGeneratedFieldProperties[] autoFieldProperties;
  81. private static readonly object PageIndexChangedEvent = new object();
  82. private static readonly object PageIndexChangingEvent = new object();
  83. private static readonly object ItemCommandEvent = new object();
  84. private static readonly object ItemCreatedEvent = new object();
  85. private static readonly object ItemDeletedEvent = new object();
  86. private static readonly object ItemDeletingEvent = new object();
  87. private static readonly object ItemInsertedEvent = new object();
  88. private static readonly object ItemInsertingEvent = new object();
  89. private static readonly object ModeChangingEvent = new object();
  90. private static readonly object ModeChangedEvent = new object();
  91. private static readonly object ItemUpdatedEvent = new object();
  92. private static readonly object ItemUpdatingEvent = new object();
  93. // Control state
  94. int pageIndex;
  95. DetailsViewMode currentMode = DetailsViewMode.ReadOnly;
  96. bool hasCurrentMode;
  97. int pageCount;
  98. public DetailsView ()
  99. {
  100. rows = new DetailsViewRowCollection (new ArrayList ());
  101. key = new DataKey (new OrderedDictionary ());
  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. if (ControlStyleCreated)
  322. return ((TableStyle) ControlStyle).BackImageUrl;
  323. return String.Empty;
  324. }
  325. set {
  326. ((TableStyle) ControlStyle).BackImageUrl = value;
  327. }
  328. }
  329. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  330. [BrowsableAttribute (false)]
  331. public virtual DetailsViewRow BottomPagerRow {
  332. get {
  333. EnsureDataBound ();
  334. return bottomPagerRow;
  335. }
  336. }
  337. [WebCategoryAttribute ("Accessibility")]
  338. [DefaultValueAttribute ("")]
  339. [LocalizableAttribute (true)]
  340. public virtual string Caption {
  341. get {
  342. object ob = ViewState ["Caption"];
  343. if (ob != null) return (string) ob;
  344. return string.Empty;
  345. }
  346. set {
  347. ViewState ["Caption"] = value;
  348. RequireBinding ();
  349. }
  350. }
  351. [WebCategoryAttribute ("Accessibility")]
  352. [DefaultValueAttribute (TableCaptionAlign.NotSet)]
  353. public virtual TableCaptionAlign CaptionAlign
  354. {
  355. get {
  356. object o = ViewState ["CaptionAlign"];
  357. if(o != null) return (TableCaptionAlign) o;
  358. return TableCaptionAlign.NotSet;
  359. }
  360. set {
  361. ViewState ["CaptionAlign"] = value;
  362. RequireBinding ();
  363. }
  364. }
  365. [WebCategoryAttribute ("Layout")]
  366. [DefaultValueAttribute (-1)]
  367. public virtual int CellPadding
  368. {
  369. get {
  370. if (ControlStyleCreated)
  371. return ((TableStyle) ControlStyle).CellPadding;
  372. return -1;
  373. }
  374. set {
  375. ((TableStyle) ControlStyle).CellPadding = value;
  376. }
  377. }
  378. [WebCategoryAttribute ("Layout")]
  379. [DefaultValueAttribute (0)]
  380. public virtual int CellSpacing
  381. {
  382. get {
  383. if (ControlStyleCreated)
  384. return ((TableStyle) ControlStyle).CellSpacing;
  385. return 0;
  386. }
  387. set {
  388. ((TableStyle) ControlStyle).CellSpacing = value;
  389. }
  390. }
  391. [DefaultValueAttribute (null)]
  392. [WebCategoryAttribute ("Styles")]
  393. [PersistenceMode (PersistenceMode.InnerProperty)]
  394. [NotifyParentProperty (true)]
  395. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  396. public TableItemStyle CommandRowStyle {
  397. get {
  398. if (commandRowStyle == null) {
  399. commandRowStyle = new TableItemStyle ();
  400. if (IsTrackingViewState)
  401. commandRowStyle.TrackViewState();
  402. }
  403. return commandRowStyle;
  404. }
  405. }
  406. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  407. [BrowsableAttribute (false)]
  408. public DetailsViewMode CurrentMode {
  409. get {
  410. return hasCurrentMode ? currentMode : DefaultMode;
  411. }
  412. private set {
  413. hasCurrentMode = true;
  414. currentMode = value;
  415. }
  416. }
  417. DetailsViewMode defaultMode = DetailsViewMode.ReadOnly;
  418. [DefaultValueAttribute (DetailsViewMode.ReadOnly)]
  419. [WebCategoryAttribute ("Behavior")]
  420. public virtual DetailsViewMode DefaultMode {
  421. get {
  422. return defaultMode;
  423. }
  424. set {
  425. defaultMode = value;
  426. RequireBinding ();
  427. }
  428. }
  429. [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  430. [MergablePropertyAttribute (false)]
  431. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  432. [DefaultValueAttribute (null)]
  433. [WebCategoryAttribute ("Misc")]
  434. public virtual DataControlFieldCollection Fields {
  435. get {
  436. if (columns == null) {
  437. columns = new DataControlFieldCollection ();
  438. columns.FieldsChanged += new EventHandler (OnFieldsChanged);
  439. if (IsTrackingViewState)
  440. ((IStateManager)columns).TrackViewState ();
  441. }
  442. return columns;
  443. }
  444. }
  445. string[] dataKeyNames = null;
  446. [DefaultValueAttribute (null)]
  447. [WebCategoryAttribute ("Data")]
  448. [TypeConverter (typeof(StringArrayConverter))]
  449. [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  450. public virtual string[] DataKeyNames
  451. {
  452. get {
  453. if (dataKeyNames == null)
  454. return emptyKeys;
  455. else
  456. return dataKeyNames;
  457. }
  458. set {
  459. dataKeyNames = value;
  460. RequireBinding ();
  461. }
  462. }
  463. [BrowsableAttribute (false)]
  464. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  465. public virtual DataKey DataKey {
  466. get {
  467. EnsureDataBound ();
  468. return key;
  469. }
  470. }
  471. [WebCategoryAttribute ("Styles")]
  472. [PersistenceMode (PersistenceMode.InnerProperty)]
  473. [NotifyParentProperty (true)]
  474. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  475. [DefaultValueAttribute (null)]
  476. public TableItemStyle EditRowStyle {
  477. get {
  478. if (editRowStyle == null) {
  479. editRowStyle = new TableItemStyle ();
  480. if (IsTrackingViewState)
  481. editRowStyle.TrackViewState();
  482. }
  483. return editRowStyle;
  484. }
  485. }
  486. [WebCategoryAttribute ("Styles")]
  487. [PersistenceMode (PersistenceMode.InnerProperty)]
  488. [NotifyParentProperty (true)]
  489. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  490. [DefaultValueAttribute (null)]
  491. public TableItemStyle EmptyDataRowStyle {
  492. get {
  493. if (emptyDataRowStyle == null) {
  494. emptyDataRowStyle = new TableItemStyle ();
  495. if (IsTrackingViewState)
  496. emptyDataRowStyle.TrackViewState();
  497. }
  498. return emptyDataRowStyle;
  499. }
  500. }
  501. [DefaultValue (null)]
  502. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  503. [PersistenceMode (PersistenceMode.InnerProperty)]
  504. [Browsable (false)]
  505. public virtual ITemplate EmptyDataTemplate {
  506. get { return emptyDataTemplate; }
  507. set { emptyDataTemplate = value; RequireBinding (); }
  508. }
  509. [LocalizableAttribute (true)]
  510. [WebCategoryAttribute ("Appearance")]
  511. [DefaultValueAttribute ("")]
  512. public virtual string EmptyDataText {
  513. get {
  514. object ob = ViewState ["EmptyDataText"];
  515. if (ob != null) return (string) ob;
  516. return string.Empty;
  517. }
  518. set {
  519. ViewState ["EmptyDataText"] = value;
  520. RequireBinding ();
  521. }
  522. }
  523. [WebCategoryAttribute ("Behavior")]
  524. [DefaultValueAttribute (false)]
  525. public virtual bool EnablePagingCallbacks {
  526. get {
  527. object ob = ViewState ["EnablePagingCallbacks"];
  528. if (ob != null) return (bool) ob;
  529. return false;
  530. }
  531. set {
  532. ViewState ["EnablePagingCallbacks"] = value;
  533. RequireBinding ();
  534. }
  535. }
  536. [WebCategoryAttribute ("Styles")]
  537. [PersistenceMode (PersistenceMode.InnerProperty)]
  538. [NotifyParentProperty (true)]
  539. [DefaultValue (null)]
  540. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  541. public TableItemStyle FieldHeaderStyle {
  542. get {
  543. if (fieldHeaderStyle == null) {
  544. fieldHeaderStyle = new TableItemStyle ();
  545. if (IsTrackingViewState)
  546. fieldHeaderStyle.TrackViewState();
  547. }
  548. return fieldHeaderStyle;
  549. }
  550. }
  551. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  552. [BrowsableAttribute (false)]
  553. public virtual DetailsViewRow FooterRow {
  554. get {
  555. EnsureChildControls ();
  556. return footerRow;
  557. }
  558. }
  559. [DefaultValue (null)]
  560. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  561. [PersistenceMode (PersistenceMode.InnerProperty)]
  562. [Browsable (false)]
  563. public virtual ITemplate FooterTemplate {
  564. get { return footerTemplate; }
  565. set { footerTemplate = value; RequireBinding (); }
  566. }
  567. [LocalizableAttribute (true)]
  568. [WebCategoryAttribute ("Appearance")]
  569. [DefaultValueAttribute ("")]
  570. public virtual string FooterText {
  571. get {
  572. object ob = ViewState ["FooterText"];
  573. if (ob != null) return (string) ob;
  574. return string.Empty;
  575. }
  576. set {
  577. ViewState ["FooterText"] = value;
  578. RequireBinding ();
  579. }
  580. }
  581. [WebCategoryAttribute ("Styles")]
  582. [PersistenceMode (PersistenceMode.InnerProperty)]
  583. [NotifyParentProperty (true)]
  584. [DefaultValue (null)]
  585. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  586. public TableItemStyle FooterStyle {
  587. get {
  588. if (footerStyle == null) {
  589. footerStyle = new TableItemStyle ();
  590. if (IsTrackingViewState)
  591. footerStyle.TrackViewState();
  592. }
  593. return footerStyle;
  594. }
  595. }
  596. [WebCategoryAttribute ("Appearance")]
  597. [DefaultValueAttribute (GridLines.Both)]
  598. public virtual GridLines GridLines {
  599. get {
  600. if (ControlStyleCreated)
  601. return ((TableStyle) ControlStyle).GridLines;
  602. return GridLines.Both;
  603. }
  604. set {
  605. ((TableStyle) ControlStyle).GridLines = value;
  606. }
  607. }
  608. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  609. [BrowsableAttribute (false)]
  610. public virtual DetailsViewRow HeaderRow {
  611. get {
  612. EnsureChildControls ();
  613. return headerRow;
  614. }
  615. }
  616. [WebCategoryAttribute ("Styles")]
  617. [PersistenceMode (PersistenceMode.InnerProperty)]
  618. [NotifyParentProperty (true)]
  619. [DefaultValue (null)]
  620. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  621. public TableItemStyle HeaderStyle {
  622. get {
  623. if (headerStyle == null) {
  624. headerStyle = new TableItemStyle ();
  625. if (IsTrackingViewState)
  626. headerStyle.TrackViewState();
  627. }
  628. return headerStyle;
  629. }
  630. }
  631. [DefaultValue (null)]
  632. [TemplateContainer (typeof(DetailsView), BindingDirection.OneWay)]
  633. [PersistenceMode (PersistenceMode.InnerProperty)]
  634. [Browsable (false)]
  635. public virtual ITemplate HeaderTemplate {
  636. get { return headerTemplate; }
  637. set { headerTemplate = value; RequireBinding (); }
  638. }
  639. [LocalizableAttribute (true)]
  640. [WebCategoryAttribute ("Appearance")]
  641. [DefaultValueAttribute ("")]
  642. public virtual string HeaderText {
  643. get {
  644. object ob = ViewState ["HeaderText"];
  645. if (ob != null) return (string) ob;
  646. return string.Empty;
  647. }
  648. set {
  649. ViewState ["HeaderText"] = value;
  650. RequireBinding ();
  651. }
  652. }
  653. [Category ("Layout")]
  654. [DefaultValueAttribute (HorizontalAlign.NotSet)]
  655. public virtual HorizontalAlign HorizontalAlign {
  656. get {
  657. if (ControlStyleCreated)
  658. return ((TableStyle) ControlStyle).HorizontalAlign;
  659. return HorizontalAlign.NotSet;
  660. }
  661. set {
  662. ((TableStyle) ControlStyle).HorizontalAlign = value;
  663. }
  664. }
  665. [WebCategoryAttribute ("Styles")]
  666. [PersistenceMode (PersistenceMode.InnerProperty)]
  667. [NotifyParentProperty (true)]
  668. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  669. [DefaultValueAttribute (null)]
  670. public TableItemStyle InsertRowStyle {
  671. get {
  672. if (insertRowStyle == null) {
  673. insertRowStyle = new TableItemStyle ();
  674. if (IsTrackingViewState)
  675. insertRowStyle.TrackViewState();
  676. }
  677. return insertRowStyle;
  678. }
  679. }
  680. [BrowsableAttribute (false)]
  681. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  682. public virtual int PageCount {
  683. get {
  684. if (pageCount != 0) return pageCount;
  685. EnsureDataBound ();
  686. return pageCount;
  687. }
  688. }
  689. [WebCategoryAttribute ("Paging")]
  690. [BindableAttribute (true, BindingDirection.OneWay)]
  691. [DefaultValueAttribute (0)]
  692. public virtual int PageIndex {
  693. get {
  694. return pageIndex;
  695. }
  696. set {
  697. if (value == pageIndex)
  698. return;
  699. pageIndex = value;
  700. RequireBinding ();
  701. }
  702. }
  703. [WebCategoryAttribute ("Paging")]
  704. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  705. [NotifyParentPropertyAttribute (true)]
  706. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  707. public virtual PagerSettings PagerSettings {
  708. get {
  709. if (pagerSettings == null) {
  710. pagerSettings = new PagerSettings (this);
  711. if (IsTrackingViewState)
  712. ((IStateManager)pagerSettings).TrackViewState ();
  713. }
  714. return pagerSettings;
  715. }
  716. }
  717. [WebCategoryAttribute ("Styles")]
  718. [PersistenceMode (PersistenceMode.InnerProperty)]
  719. [NotifyParentProperty (true)]
  720. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  721. public TableItemStyle PagerStyle {
  722. get {
  723. if (pagerStyle == null) {
  724. pagerStyle = new TableItemStyle ();
  725. if (IsTrackingViewState)
  726. pagerStyle.TrackViewState();
  727. }
  728. return pagerStyle;
  729. }
  730. }
  731. [DefaultValue (null)]
  732. /* DataControlPagerCell isnt specified in the docs */
  733. //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
  734. [PersistenceMode (PersistenceMode.InnerProperty)]
  735. [Browsable (false)]
  736. public virtual ITemplate PagerTemplate {
  737. get { return pagerTemplate; }
  738. set { pagerTemplate = value; RequireBinding (); }
  739. }
  740. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  741. [BrowsableAttribute (false)]
  742. public virtual DetailsViewRowCollection Rows {
  743. get {
  744. EnsureChildControls ();
  745. return rows;
  746. }
  747. }
  748. [WebCategoryAttribute ("Styles")]
  749. [PersistenceMode (PersistenceMode.InnerProperty)]
  750. [NotifyParentProperty (true)]
  751. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  752. [DefaultValue (null)]
  753. public TableItemStyle RowStyle {
  754. get {
  755. if (rowStyle == null) {
  756. rowStyle = new TableItemStyle ();
  757. if (IsTrackingViewState)
  758. rowStyle.TrackViewState();
  759. }
  760. return rowStyle;
  761. }
  762. }
  763. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  764. [BrowsableAttribute (false)]
  765. public object SelectedValue {
  766. get { return DataKey.Value; }
  767. }
  768. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  769. [BrowsableAttribute (false)]
  770. public virtual DetailsViewRow TopPagerRow {
  771. get {
  772. EnsureDataBound ();
  773. return topPagerRow;
  774. }
  775. }
  776. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  777. [BrowsableAttribute (false)]
  778. public virtual object DataItem {
  779. get {
  780. EnsureDataBound ();
  781. return dataItem;
  782. }
  783. }
  784. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  785. [BrowsableAttribute (false)]
  786. public int DataItemCount {
  787. get { return PageCount; }
  788. }
  789. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  790. [BrowsableAttribute (false)]
  791. public virtual int DataItemIndex {
  792. get { return PageIndex; }
  793. }
  794. int IDataItemContainer.DisplayIndex {
  795. get { return PageIndex; }
  796. }
  797. public virtual bool IsBindableType (Type type)
  798. {
  799. return type.IsPrimitive || type == typeof (string) || type == typeof (DateTime) || type == typeof (Guid) || type == typeof (Decimal);
  800. }
  801. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  802. {
  803. DataSourceSelectArguments arg = new DataSourceSelectArguments ();
  804. DataSourceView view = GetData ();
  805. if (AllowPaging && view.CanPage) {
  806. arg.StartRowIndex = PageIndex;
  807. if (view.CanRetrieveTotalRowCount) {
  808. arg.RetrieveTotalRowCount = true;
  809. arg.MaximumRows = 1;
  810. }
  811. else {
  812. arg.MaximumRows = -1;
  813. }
  814. }
  815. return arg;
  816. }
  817. protected virtual ICollection CreateFieldSet (object dataItem, bool useDataSource)
  818. {
  819. ArrayList fields = new ArrayList ();
  820. if (AutoGenerateRows) {
  821. if (useDataSource) {
  822. if (dataItem != null)
  823. fields.AddRange (CreateAutoGeneratedRows (dataItem));
  824. } else {
  825. if (autoFieldProperties != null) {
  826. foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
  827. fields.Add (CreateAutoGeneratedRow (props));
  828. }
  829. }
  830. }
  831. fields.AddRange (Fields);
  832. if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateInsertButton) {
  833. CommandField field = new CommandField ();
  834. field.ShowEditButton = AutoGenerateEditButton;
  835. field.ShowDeleteButton = AutoGenerateDeleteButton;
  836. field.ShowInsertButton = AutoGenerateInsertButton;
  837. fields.Add (field);
  838. }
  839. return fields;
  840. }
  841. protected virtual ICollection CreateAutoGeneratedRows (object dataItem)
  842. {
  843. ArrayList list = new ArrayList ();
  844. autoFieldProperties = CreateAutoFieldProperties (dataItem);
  845. foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
  846. list.Add (CreateAutoGeneratedRow (props));
  847. return list;
  848. }
  849. protected virtual AutoGeneratedField CreateAutoGeneratedRow (AutoGeneratedFieldProperties fieldProperties)
  850. {
  851. return new AutoGeneratedField (fieldProperties);
  852. }
  853. AutoGeneratedFieldProperties[] CreateAutoFieldProperties (object dataItem)
  854. {
  855. PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
  856. ArrayList retVal = new ArrayList();
  857. if (props != null && props.Count > 0)
  858. {
  859. foreach (PropertyDescriptor current in props) {
  860. if (IsBindableType (current.PropertyType)) {
  861. AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
  862. ((IStateManager)field).TrackViewState();
  863. field.Name = current.Name;
  864. field.DataField = current.Name;
  865. field.IsReadOnly = current.IsReadOnly;
  866. field.Type = current.PropertyType;
  867. retVal.Add (field);
  868. }
  869. }
  870. }
  871. if (retVal.Count > 0)
  872. return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
  873. else
  874. return new AutoGeneratedFieldProperties [0];
  875. }
  876. protected virtual DetailsViewRow CreateRow (int rowIndex, DataControlRowType rowType, DataControlRowState rowState)
  877. {
  878. DetailsViewRow row;
  879. if (rowType == DataControlRowType.Pager)
  880. row = new DetailsViewPagerRow (rowIndex, rowType, rowState);
  881. else
  882. row = new DetailsViewRow (rowIndex, rowType, rowState);
  883. OnItemCreated (EventArgs.Empty);
  884. return row;
  885. }
  886. void RequireBinding ()
  887. {
  888. if (Initialized) {
  889. RequiresDataBinding = true;
  890. pageCount = 0;
  891. }
  892. }
  893. protected virtual Table CreateTable ()
  894. {
  895. return new ContainedTable (this);
  896. }
  897. protected override Style CreateControlStyle ()
  898. {
  899. TableStyle style = new TableStyle (ViewState);
  900. style.GridLines = GridLines.Both;
  901. style.CellSpacing = 0;
  902. return style;
  903. }
  904. protected override int CreateChildControls (IEnumerable data, bool dataBinding)
  905. {
  906. PagedDataSource dataSource;
  907. if (dataBinding) {
  908. DataSourceView view = GetData ();
  909. dataSource = new PagedDataSource ();
  910. dataSource.DataSource = data;
  911. if (AllowPaging) {
  912. dataSource.AllowPaging = true;
  913. dataSource.PageSize = 1;
  914. dataSource.CurrentPageIndex = PageIndex;
  915. if (view.CanPage) {
  916. dataSource.AllowServerPaging = true;
  917. if (view.CanRetrieveTotalRowCount)
  918. dataSource.VirtualCount = SelectArguments.TotalRowCount;
  919. }
  920. }
  921. pageCount = dataSource.DataSourceCount;
  922. }
  923. else
  924. {
  925. dataSource = new PagedDataSource ();
  926. dataSource.DataSource = data;
  927. if (AllowPaging) {
  928. dataSource.AllowPaging = true;
  929. dataSource.PageSize = 1;
  930. dataSource.CurrentPageIndex = PageIndex;
  931. }
  932. }
  933. bool showPager = AllowPaging && (PageCount > 1);
  934. Controls.Clear ();
  935. table = CreateTable ();
  936. Controls.Add (table);
  937. ArrayList list = new ArrayList ();
  938. // Gets the current data item
  939. IEnumerator e = dataSource.GetEnumerator ();
  940. if (e.MoveNext ())
  941. dataItem = e.Current;
  942. else
  943. dataItem = null;
  944. // Creates the set of fields to show
  945. ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding);
  946. DataControlField[] fields = new DataControlField [fieldCollection.Count];
  947. fieldCollection.CopyTo (fields, 0);
  948. foreach (DataControlField field in fields) {
  949. field.Initialize (false, this);
  950. if (EnablePagingCallbacks)
  951. field.ValidateSupportsCallback ();
  952. }
  953. // Main table creation
  954. headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal);
  955. DataControlFieldCell headerCell = new DataControlFieldCell (null);
  956. headerCell.ColumnSpan = 2;
  957. if (headerTemplate != null)
  958. headerTemplate.InstantiateIn (headerCell);
  959. else
  960. headerCell.Text = HeaderText;
  961. headerRow.Cells.Add (headerCell);
  962. table.Rows.Add (headerRow);
  963. if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
  964. topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
  965. InitializePager (topPagerRow, dataSource);
  966. table.Rows.Add (topPagerRow);
  967. }
  968. if (dataSource.Count > 0) {
  969. foreach (DataControlField field in fields) {
  970. DataControlRowState rstate = GetRowState (list.Count);
  971. DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate);
  972. InitializeRow (row, field);
  973. table.Rows.Add (row);
  974. list.Add (row);
  975. }
  976. if (!dataBinding) {
  977. if (CurrentMode == DetailsViewMode.Edit)
  978. oldEditValues = new DataKey (new OrderedDictionary ());
  979. key = new DataKey (new OrderedDictionary (), DataKeyNames);
  980. }
  981. } else {
  982. table.Rows.Add (CreateEmptyrRow ());
  983. }
  984. rows = new DetailsViewRowCollection (list);
  985. footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal);
  986. DataControlFieldCell footerCell = new DataControlFieldCell (null);
  987. footerCell.ColumnSpan = 2;
  988. if (footerTemplate != null)
  989. footerTemplate.InstantiateIn (footerCell);
  990. else
  991. footerCell.Text = FooterText;
  992. footerRow.Cells.Add (footerCell);
  993. table.Rows.Add (footerRow);
  994. if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
  995. bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
  996. InitializePager (bottomPagerRow, dataSource);
  997. table.Rows.Add (bottomPagerRow);
  998. }
  999. if (dataBinding)
  1000. DataBind (false);
  1001. return dataSource.DataSourceCount;
  1002. }
  1003. [MonoTODO]
  1004. protected override void EnsureDataBound ()
  1005. {
  1006. base.EnsureDataBound ();
  1007. }
  1008. DataControlRowState GetRowState (int index)
  1009. {
  1010. DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
  1011. if (CurrentMode == DetailsViewMode.Edit) rstate |= DataControlRowState.Edit;
  1012. else if (CurrentMode == DetailsViewMode.Insert) rstate |= DataControlRowState.Insert;
  1013. return rstate;
  1014. }
  1015. protected virtual void InitializePager (DetailsViewRow row, PagedDataSource dataSource)
  1016. {
  1017. TableCell cell = new TableCell ();
  1018. cell.ColumnSpan = 2;
  1019. if (pagerTemplate != null)
  1020. pagerTemplate.InstantiateIn (cell);
  1021. else
  1022. cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
  1023. row.Cells.Add (cell);
  1024. }
  1025. DetailsViewRow CreateEmptyrRow ()
  1026. {
  1027. DetailsViewRow row = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
  1028. TableCell cell = new TableCell ();
  1029. cell.ColumnSpan = 2;
  1030. if (emptyDataTemplate != null)
  1031. emptyDataTemplate.InstantiateIn (cell);
  1032. else
  1033. cell.Text = EmptyDataText;
  1034. row.Cells.Add (cell);
  1035. return row;
  1036. }
  1037. protected virtual void InitializeRow (DetailsViewRow row, DataControlField field)
  1038. {
  1039. row.ContainingField = field;
  1040. DataControlFieldCell cell;
  1041. if (field.ShowHeader) {
  1042. cell = new DataControlFieldCell (field);
  1043. row.Cells.Add (cell);
  1044. field.InitializeCell (cell, DataControlCellType.Header, row.RowState, row.RowIndex);
  1045. }
  1046. cell = new DataControlFieldCell (field);
  1047. if (!field.ShowHeader)
  1048. cell.ColumnSpan = 2;
  1049. row.Cells.Add (cell);
  1050. field.InitializeCell (cell, DataControlCellType.DataCell, row.RowState, row.RowIndex);
  1051. if (CurrentMode == DetailsViewMode.Insert && !field.InsertVisible)
  1052. row.Visible = false;
  1053. }
  1054. IOrderedDictionary CreateRowDataKey (object dataItem)
  1055. {
  1056. if (cachedKeyProperties == null) {
  1057. PropertyDescriptorCollection props = TypeDescriptor.GetProperties (dataItem);
  1058. cachedKeyProperties = new PropertyDescriptor [DataKeyNames.Length];
  1059. for (int n=0; n<DataKeyNames.Length; n++) {
  1060. PropertyDescriptor p = props [DataKeyNames[n]];
  1061. if (p == null)
  1062. new InvalidOperationException ("Property '" + DataKeyNames[n] + "' not found in object of type " + dataItem.GetType());
  1063. cachedKeyProperties [n] = p;
  1064. }
  1065. }
  1066. OrderedDictionary dic = new OrderedDictionary ();
  1067. foreach (PropertyDescriptor p in cachedKeyProperties)
  1068. dic [p.Name] = p.GetValue (dataItem);
  1069. return dic;
  1070. }
  1071. IOrderedDictionary GetRowValues (bool includeReadOnlyFields, bool includePrimaryKey)
  1072. {
  1073. OrderedDictionary dic = new OrderedDictionary ();
  1074. ExtractRowValues (dic, includeReadOnlyFields, includePrimaryKey);
  1075. return dic;
  1076. }
  1077. protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, bool includeReadOnlyFields, bool includePrimaryKey)
  1078. {
  1079. foreach (DetailsViewRow row in Rows) {
  1080. if (row.Cells.Count < 1) continue;
  1081. DataControlFieldCell c = row.Cells[row.Cells.Count-1] as DataControlFieldCell;
  1082. if (c != null)
  1083. c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
  1084. }
  1085. if (!includePrimaryKey && DataKeyNames != null)
  1086. foreach (string key in DataKeyNames)
  1087. fieldValues.Remove (key);
  1088. }
  1089. protected override HtmlTextWriterTag TagKey {
  1090. get {
  1091. if (EnablePagingCallbacks)
  1092. return HtmlTextWriterTag.Div;
  1093. else
  1094. return HtmlTextWriterTag.Table;
  1095. }
  1096. }
  1097. public sealed override void DataBind ()
  1098. {
  1099. if (CurrentMode == DetailsViewMode.Insert) {
  1100. RequiresDataBinding = false;
  1101. PerformDataBinding (new object [] { null });
  1102. return;
  1103. }
  1104. cachedKeyProperties = null;
  1105. base.DataBind ();
  1106. if (dataItem != null) {
  1107. if (CurrentMode == DetailsViewMode.Edit)
  1108. oldEditValues = new DataKey (GetRowValues (false, true));
  1109. else
  1110. oldEditValues = new DataKey (new OrderedDictionary ());
  1111. key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
  1112. }
  1113. }
  1114. protected internal override void PerformDataBinding (IEnumerable data)
  1115. {
  1116. base.PerformDataBinding (data);
  1117. }
  1118. protected internal virtual void PrepareControlHierarchy ()
  1119. {
  1120. if (table == null)
  1121. return;
  1122. table.Caption = Caption;
  1123. table.CaptionAlign = CaptionAlign;
  1124. foreach (DetailsViewRow row in table.Rows) {
  1125. switch (row.RowType) {
  1126. case DataControlRowType.Header:
  1127. if (headerStyle != null && !headerStyle.IsEmpty)
  1128. row.ControlStyle.CopyFrom (headerStyle);
  1129. break;
  1130. case DataControlRowType.Footer:
  1131. if (footerStyle != null && !footerStyle.IsEmpty)
  1132. row.ControlStyle.CopyFrom (footerStyle);
  1133. break;
  1134. case DataControlRowType.Pager:
  1135. if (pagerStyle != null && !pagerStyle.IsEmpty)
  1136. row.ControlStyle.CopyFrom (pagerStyle);
  1137. break;
  1138. case DataControlRowType.EmptyDataRow:
  1139. if (emptyDataRowStyle != null && !emptyDataRowStyle.IsEmpty)
  1140. row.ControlStyle.CopyFrom (emptyDataRowStyle);
  1141. break;
  1142. case DataControlRowType.DataRow:
  1143. if (rowStyle != null && !rowStyle.IsEmpty)
  1144. row.ControlStyle.CopyFrom (rowStyle);
  1145. if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null && !alternatingRowStyle.IsEmpty)
  1146. row.ControlStyle.CopyFrom (alternatingRowStyle);
  1147. if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null && !editRowStyle.IsEmpty)
  1148. row.ControlStyle.CopyFrom (editRowStyle);
  1149. if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null && !insertRowStyle.IsEmpty)
  1150. row.ControlStyle.CopyFrom (insertRowStyle);
  1151. break;
  1152. default:
  1153. break;
  1154. }
  1155. if ((row.ContainingField is CommandField) && commandRowStyle != null && !commandRowStyle.IsEmpty)
  1156. row.ControlStyle.CopyFrom (commandRowStyle);
  1157. for (int n = 0; n < row.Cells.Count; n++) {
  1158. DataControlFieldCell fcell = row.Cells [n] as DataControlFieldCell;
  1159. if (fcell != null && fcell.ContainingField != null) {
  1160. DataControlField field = fcell.ContainingField;
  1161. if (n == 0 && field.ShowHeader) {
  1162. if (fieldHeaderStyle != null && !fieldHeaderStyle.IsEmpty)
  1163. fcell.ControlStyle.CopyFrom (fieldHeaderStyle);
  1164. if (field.HeaderStyleCreated && !field.HeaderStyle.IsEmpty)
  1165. fcell.ControlStyle.CopyFrom (field.HeaderStyle);
  1166. }
  1167. else {
  1168. if (field.ControlStyleCreated && !field.ControlStyle.IsEmpty)
  1169. foreach (Control c in fcell.Controls) {
  1170. WebControl wc = c as WebControl;
  1171. if (wc != null)
  1172. wc.ControlStyle.MergeWith (field.ControlStyle);
  1173. }
  1174. if (field.ItemStyleCreated && !field.ItemStyle.IsEmpty)
  1175. fcell.ControlStyle.CopyFrom (field.ItemStyle);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. }
  1181. protected internal override void OnInit (EventArgs e)
  1182. {
  1183. Page.RegisterRequiresControlState (this);
  1184. base.OnInit (e);
  1185. }
  1186. void OnFieldsChanged (object sender, EventArgs args)
  1187. {
  1188. RequireBinding ();
  1189. }
  1190. protected override void OnDataSourceViewChanged (object sender, EventArgs e)
  1191. {
  1192. base.OnDataSourceViewChanged (sender, e);
  1193. RequireBinding ();
  1194. }
  1195. protected override bool OnBubbleEvent (object source, EventArgs e)
  1196. {
  1197. DetailsViewCommandEventArgs args = e as DetailsViewCommandEventArgs;
  1198. if (args != null) {
  1199. OnItemCommand (args);
  1200. ProcessEvent (args.CommandName, args.CommandArgument as string);
  1201. return true;
  1202. }
  1203. return base.OnBubbleEvent (source, e);
  1204. }
  1205. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  1206. {
  1207. RaisePostBackEvent (eventArgument);
  1208. }
  1209. // TODO: This is prolly obsolete
  1210. protected virtual void RaisePostBackEvent (string eventArgument)
  1211. {
  1212. int i = eventArgument.IndexOf ('$');
  1213. if (i != -1)
  1214. ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
  1215. else
  1216. ProcessEvent (eventArgument, null);
  1217. }
  1218. void ProcessEvent (string eventName, string param)
  1219. {
  1220. switch (eventName)
  1221. {
  1222. case DataControlCommands.PageCommandName:
  1223. int newIndex = -1;
  1224. switch (param) {
  1225. case DataControlCommands.FirstPageCommandArgument:
  1226. newIndex = 0;
  1227. break;
  1228. case DataControlCommands.LastPageCommandArgument:
  1229. newIndex = PageCount - 1;
  1230. break;
  1231. case DataControlCommands.NextPageCommandArgument:
  1232. newIndex = PageIndex + 1;
  1233. break;
  1234. case DataControlCommands.PreviousPageCommandArgument:
  1235. newIndex = PageIndex - 1;
  1236. break;
  1237. default:
  1238. int paramIndex = 0;
  1239. int.TryParse (param, out paramIndex);
  1240. newIndex = paramIndex - 1;
  1241. break;
  1242. }
  1243. ShowPage (newIndex);
  1244. break;
  1245. case DataControlCommands.FirstPageCommandArgument:
  1246. ShowPage (0);
  1247. break;
  1248. case DataControlCommands.LastPageCommandArgument:
  1249. ShowPage (PageCount - 1);
  1250. break;
  1251. case DataControlCommands.NextPageCommandArgument:
  1252. if (PageIndex < PageCount - 1)
  1253. ShowPage (PageIndex + 1);
  1254. break;
  1255. case DataControlCommands.PreviousPageCommandArgument:
  1256. if (PageIndex > 0)
  1257. ShowPage (PageIndex - 1);
  1258. break;
  1259. case DataControlCommands.EditCommandName:
  1260. ChangeMode (DetailsViewMode.Edit);
  1261. break;
  1262. case DataControlCommands.NewCommandName:
  1263. ChangeMode (DetailsViewMode.Insert);
  1264. break;
  1265. case DataControlCommands.UpdateCommandName:
  1266. UpdateItem (param, true);
  1267. break;
  1268. case DataControlCommands.CancelCommandName:
  1269. CancelEdit ();
  1270. break;
  1271. case DataControlCommands.DeleteCommandName:
  1272. DeleteItem ();
  1273. break;
  1274. case DataControlCommands.InsertCommandName:
  1275. InsertItem (true);
  1276. break;
  1277. }
  1278. }
  1279. void ShowPage (int newIndex)
  1280. {
  1281. DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
  1282. OnPageIndexChanging (args);
  1283. if (!args.Cancel) {
  1284. if (args.NewPageIndex < 0 || args.NewPageIndex >= PageCount)
  1285. return;
  1286. EndRowEdit (false);
  1287. PageIndex = args.NewPageIndex;
  1288. OnPageIndexChanged (EventArgs.Empty);
  1289. }
  1290. }
  1291. public void ChangeMode (DetailsViewMode newMode)
  1292. {
  1293. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
  1294. OnModeChanging (args);
  1295. if (!args.Cancel) {
  1296. CurrentMode = args.NewMode;
  1297. OnModeChanged (EventArgs.Empty);
  1298. RequireBinding ();
  1299. }
  1300. }
  1301. void CancelEdit ()
  1302. {
  1303. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
  1304. OnModeChanging (args);
  1305. if (!args.Cancel) {
  1306. EndRowEdit ();
  1307. }
  1308. }
  1309. public virtual void UpdateItem (bool causesValidation)
  1310. {
  1311. UpdateItem (null, causesValidation);
  1312. }
  1313. void UpdateItem (string param, bool causesValidation)
  1314. {
  1315. if (causesValidation)
  1316. Page.Validate ();
  1317. if (CurrentMode != DetailsViewMode.Edit) throw new NotSupportedException ();
  1318. currentEditOldValues = oldEditValues.Values;
  1319. currentEditRowKeys = DataKey.Values;
  1320. currentEditNewValues = GetRowValues (false, false);
  1321. DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1322. OnItemUpdating (args);
  1323. if (!args.Cancel) {
  1324. DataSourceView view = GetData ();
  1325. if (view == null)
  1326. throw new HttpException ("The DataSourceView associated to data bound control was null");
  1327. if (view.CanUpdate)
  1328. view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
  1329. }
  1330. else
  1331. EndRowEdit ();
  1332. }
  1333. bool UpdateCallback (int recordsAffected, Exception exception)
  1334. {
  1335. DetailsViewUpdatedEventArgs dargs = new DetailsViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1336. OnItemUpdated (dargs);
  1337. if (!dargs.KeepInEditMode)
  1338. EndRowEdit ();
  1339. return dargs.ExceptionHandled;
  1340. }
  1341. public virtual void InsertItem (bool causesValidation)
  1342. {
  1343. InsertItem (null, causesValidation);
  1344. }
  1345. void InsertItem (string param, bool causesValidation)
  1346. {
  1347. if (causesValidation)
  1348. Page.Validate ();
  1349. if (CurrentMode != DetailsViewMode.Insert) throw new NotSupportedException ();
  1350. currentEditNewValues = GetRowValues (false, true);
  1351. DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
  1352. OnItemInserting (args);
  1353. if (!args.Cancel) {
  1354. DataSourceView view = GetData ();
  1355. if (view != null && view.CanInsert)
  1356. view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
  1357. }
  1358. else
  1359. EndRowEdit ();
  1360. }
  1361. bool InsertCallback (int recordsAffected, Exception exception)
  1362. {
  1363. DetailsViewInsertedEventArgs dargs = new DetailsViewInsertedEventArgs (recordsAffected, exception, currentEditNewValues);
  1364. OnItemInserted (dargs);
  1365. if (!dargs.KeepInInsertMode)
  1366. EndRowEdit ();
  1367. return dargs.ExceptionHandled;
  1368. }
  1369. public virtual void DeleteItem ()
  1370. {
  1371. currentEditRowKeys = DataKey == null ? null : DataKey.Values;
  1372. currentEditNewValues = GetRowValues (true, true);
  1373. DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
  1374. OnItemDeleting (args);
  1375. if (!args.Cancel) {
  1376. if (PageIndex == PageCount - 1)
  1377. PageIndex --;
  1378. RequireBinding ();
  1379. DataSourceView view = GetData ();
  1380. if (view != null && view.CanDelete)
  1381. view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
  1382. else {
  1383. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
  1384. OnItemDeleted (dargs);
  1385. }
  1386. }
  1387. }
  1388. bool DeleteCallback (int recordsAffected, Exception exception)
  1389. {
  1390. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
  1391. OnItemDeleted (dargs);
  1392. return dargs.ExceptionHandled;
  1393. }
  1394. void EndRowEdit ()
  1395. {
  1396. EndRowEdit (true);
  1397. }
  1398. void EndRowEdit (bool switchToDefaultMode) {
  1399. if (switchToDefaultMode)
  1400. ChangeMode (DefaultMode);
  1401. oldEditValues = new DataKey (new OrderedDictionary ());
  1402. currentEditRowKeys = null;
  1403. currentEditOldValues = null;
  1404. currentEditNewValues = null;
  1405. RequireBinding ();
  1406. }
  1407. protected internal override void LoadControlState (object ob)
  1408. {
  1409. if (ob == null) return;
  1410. object[] state = (object[]) ob;
  1411. base.LoadControlState (state[0]);
  1412. pageIndex = (int) state[1];
  1413. pageCount = (int) state[2];
  1414. CurrentMode = (DetailsViewMode) state[3];
  1415. dataKeyNames = (string[]) state[4];
  1416. defaultMode = (DetailsViewMode) state[5];
  1417. }
  1418. protected internal override object SaveControlState ()
  1419. {
  1420. object bstate = base.SaveControlState ();
  1421. return new object[] {
  1422. bstate, pageIndex, pageCount, CurrentMode, dataKeyNames, defaultMode
  1423. };
  1424. }
  1425. protected override void TrackViewState()
  1426. {
  1427. base.TrackViewState();
  1428. if (columns != null) ((IStateManager)columns).TrackViewState();
  1429. if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
  1430. if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
  1431. if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
  1432. if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
  1433. if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
  1434. if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
  1435. if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
  1436. if (insertRowStyle != null) ((IStateManager)insertRowStyle).TrackViewState();
  1437. if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
  1438. if (key != null) ((IStateManager)key).TrackViewState();
  1439. if (autoFieldProperties != null) {
  1440. foreach (IStateManager sm in autoFieldProperties)
  1441. sm.TrackViewState ();
  1442. }
  1443. }
  1444. protected override object SaveViewState()
  1445. {
  1446. object[] states = new object [14];
  1447. states[0] = base.SaveViewState();
  1448. states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
  1449. states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
  1450. states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
  1451. states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
  1452. states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
  1453. states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
  1454. states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
  1455. states[8] = (insertRowStyle == null ? null : ((IStateManager)insertRowStyle).SaveViewState());
  1456. states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
  1457. states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
  1458. states[11] = (key == null ? null : ((IStateManager)key).SaveViewState());
  1459. states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
  1460. if (autoFieldProperties != null) {
  1461. object[] data = new object [autoFieldProperties.Length];
  1462. bool allNull = true;
  1463. for (int n=0; n<data.Length; n++) {
  1464. data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
  1465. if (data [n] != null) allNull = false;
  1466. }
  1467. if (!allNull) states [13] = data;
  1468. }
  1469. for (int i = states.Length - 1; i >= 0; i--) {
  1470. if (states [i] != null)
  1471. return states;
  1472. }
  1473. return null;
  1474. }
  1475. protected override void LoadViewState (object savedState)
  1476. {
  1477. if (savedState == null) {
  1478. base.LoadViewState (null);
  1479. return;
  1480. }
  1481. object [] states = (object []) savedState;
  1482. if (states[13] != null) {
  1483. object[] data = (object[]) states [13];
  1484. autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
  1485. for (int n=0; n<data.Length; n++) {
  1486. IStateManager p = new AutoGeneratedFieldProperties ();
  1487. p.TrackViewState ();
  1488. p.LoadViewState (data [n]);
  1489. autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
  1490. }
  1491. }
  1492. base.LoadViewState (states[0]);
  1493. EnsureChildControls ();
  1494. if (states[1] != null) ((IStateManager)Fields).LoadViewState (states[1]);
  1495. if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
  1496. if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
  1497. if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
  1498. if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
  1499. if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
  1500. if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
  1501. if (states[8] != null) ((IStateManager)InsertRowStyle).LoadViewState (states[8]);
  1502. if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
  1503. if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
  1504. if (states[11] != null) ((IStateManager)DataKey).LoadViewState (states[11]);
  1505. if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
  1506. }
  1507. void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
  1508. {
  1509. RaiseCallbackEvent (eventArgs);
  1510. }
  1511. protected virtual void RaiseCallbackEvent (string eventArgs)
  1512. {
  1513. string[] clientData = eventArgs.Split ('|');
  1514. PageIndex = int.Parse (clientData[0]);
  1515. RaisePostBackEvent (clientData[1]);
  1516. DataBind ();
  1517. }
  1518. string ICallbackEventHandler.GetCallbackResult ()
  1519. {
  1520. return GetCallbackResult ();
  1521. }
  1522. protected virtual string GetCallbackResult ()
  1523. {
  1524. PrepareControlHierarchy ();
  1525. StringWriter sw = new StringWriter ();
  1526. sw.Write (PageIndex.ToString () + '|');
  1527. HtmlTextWriter writer = new HtmlTextWriter (sw);
  1528. RenderGrid (writer);
  1529. return sw.ToString ();
  1530. }
  1531. protected virtual string GetCallbackScript (IButtonControl buttonControl, string argument)
  1532. {
  1533. if (EnablePagingCallbacks)
  1534. return "javascript:DetailsView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
  1535. else
  1536. return null;
  1537. }
  1538. string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
  1539. {
  1540. return GetCallbackScript (control, argument);
  1541. }
  1542. protected override void OnPagePreLoad (object sender, EventArgs e)
  1543. {
  1544. base.OnPagePreLoad (sender, e);
  1545. if (Page.IsPostBack && EnablePagingCallbacks) {
  1546. int page;
  1547. if (int.TryParse (Page.Request.Form [ClientID + "_Page"], out page))
  1548. PageIndex = page;
  1549. }
  1550. }
  1551. protected internal override void OnPreRender (EventArgs e)
  1552. {
  1553. base.OnPreRender (e);
  1554. if (EnablePagingCallbacks)
  1555. {
  1556. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(DetailsView), "DetailsView.js")) {
  1557. string url = Page.ClientScript.GetWebResourceUrl (typeof(DetailsView), "DetailsView.js");
  1558. Page.ClientScript.RegisterClientScriptInclude (typeof(DetailsView), "DetailsView.js", url);
  1559. }
  1560. Page.ClientScript.RegisterHiddenField (ClientID + "_Page", PageIndex.ToString ());
  1561. string cgrid = ClientID + "_data";
  1562. string script = string.Format ("var {0} = new Object ();\n", cgrid);
  1563. script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
  1564. script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
  1565. Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
  1566. // Make sure the basic script infrastructure is rendered
  1567. Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
  1568. Page.ClientScript.GetPostBackClientHyperlink (this, "");
  1569. }
  1570. }
  1571. protected internal override void Render (HtmlTextWriter writer)
  1572. {
  1573. PrepareControlHierarchy ();
  1574. if (EnablePagingCallbacks)
  1575. base.RenderBeginTag (writer);
  1576. else
  1577. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1578. RenderGrid (writer);
  1579. if (EnablePagingCallbacks)
  1580. base.RenderEndTag (writer);
  1581. else
  1582. writer.RenderEndTag ();
  1583. }
  1584. void RenderGrid (HtmlTextWriter writer)
  1585. {
  1586. if (table == null)
  1587. return;
  1588. table.Render (writer);
  1589. }
  1590. PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
  1591. {
  1592. if (control == null)
  1593. throw new ArgumentNullException ("control");
  1594. if (control.CausesValidation)
  1595. throw new InvalidOperationException ("A button that causes validation in DetailsView '" + ID + "' is attempting to use the container GridView as the post back target. The button should either turn off validation or use itself as the post back container.");
  1596. PostBackOptions options = new PostBackOptions (this);
  1597. options.Argument = control.CommandName + "$" + control.CommandArgument;
  1598. options.RequiresJavaScriptProtocol = true;
  1599. return options;
  1600. }
  1601. }
  1602. }
  1603. #endif