DetailsView.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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. key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
  1110. }
  1111. }
  1112. protected internal override void PerformDataBinding (IEnumerable data)
  1113. {
  1114. base.PerformDataBinding (data);
  1115. }
  1116. protected internal virtual void PrepareControlHierarchy ()
  1117. {
  1118. if (table == null)
  1119. return;
  1120. table.Caption = Caption;
  1121. table.CaptionAlign = CaptionAlign;
  1122. foreach (DetailsViewRow row in table.Rows) {
  1123. switch (row.RowType) {
  1124. case DataControlRowType.Header:
  1125. if (headerStyle != null && !headerStyle.IsEmpty)
  1126. row.ControlStyle.CopyFrom (headerStyle);
  1127. break;
  1128. case DataControlRowType.Footer:
  1129. if (footerStyle != null && !footerStyle.IsEmpty)
  1130. row.ControlStyle.CopyFrom (footerStyle);
  1131. break;
  1132. case DataControlRowType.Pager:
  1133. if (pagerStyle != null && !pagerStyle.IsEmpty)
  1134. row.ControlStyle.CopyFrom (pagerStyle);
  1135. break;
  1136. case DataControlRowType.EmptyDataRow:
  1137. if (emptyDataRowStyle != null && !emptyDataRowStyle.IsEmpty)
  1138. row.ControlStyle.CopyFrom (emptyDataRowStyle);
  1139. break;
  1140. case DataControlRowType.DataRow:
  1141. if (rowStyle != null && !rowStyle.IsEmpty)
  1142. row.ControlStyle.CopyFrom (rowStyle);
  1143. if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null && !alternatingRowStyle.IsEmpty)
  1144. row.ControlStyle.CopyFrom (alternatingRowStyle);
  1145. if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null && !editRowStyle.IsEmpty)
  1146. row.ControlStyle.CopyFrom (editRowStyle);
  1147. if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null && !insertRowStyle.IsEmpty)
  1148. row.ControlStyle.CopyFrom (insertRowStyle);
  1149. break;
  1150. default:
  1151. break;
  1152. }
  1153. if ((row.ContainingField is CommandField) && commandRowStyle != null && !commandRowStyle.IsEmpty)
  1154. row.ControlStyle.CopyFrom (commandRowStyle);
  1155. for (int n = 0; n < row.Cells.Count; n++) {
  1156. DataControlFieldCell fcell = row.Cells [n] as DataControlFieldCell;
  1157. if (fcell != null && fcell.ContainingField != null) {
  1158. DataControlField field = fcell.ContainingField;
  1159. if (n == 0 && field.ShowHeader) {
  1160. if (fieldHeaderStyle != null && !fieldHeaderStyle.IsEmpty)
  1161. fcell.ControlStyle.CopyFrom (fieldHeaderStyle);
  1162. if (field.HeaderStyleCreated && !field.HeaderStyle.IsEmpty)
  1163. fcell.ControlStyle.CopyFrom (field.HeaderStyle);
  1164. }
  1165. else {
  1166. if (field.ControlStyleCreated && !field.ControlStyle.IsEmpty)
  1167. foreach (Control c in fcell.Controls) {
  1168. WebControl wc = c as WebControl;
  1169. if (wc != null)
  1170. wc.ControlStyle.MergeWith (field.ControlStyle);
  1171. }
  1172. if (field.ItemStyleCreated && !field.ItemStyle.IsEmpty)
  1173. fcell.ControlStyle.CopyFrom (field.ItemStyle);
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. protected internal override void OnInit (EventArgs e)
  1180. {
  1181. Page.RegisterRequiresControlState (this);
  1182. base.OnInit (e);
  1183. }
  1184. void OnFieldsChanged (object sender, EventArgs args)
  1185. {
  1186. RequireBinding ();
  1187. }
  1188. protected override void OnDataSourceViewChanged (object sender, EventArgs e)
  1189. {
  1190. base.OnDataSourceViewChanged (sender, e);
  1191. RequireBinding ();
  1192. }
  1193. protected override bool OnBubbleEvent (object source, EventArgs e)
  1194. {
  1195. DetailsViewCommandEventArgs args = e as DetailsViewCommandEventArgs;
  1196. if (args != null) {
  1197. OnItemCommand (args);
  1198. ProcessEvent (args.CommandName, args.CommandArgument as string);
  1199. }
  1200. return base.OnBubbleEvent (source, e);
  1201. }
  1202. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  1203. {
  1204. RaisePostBackEvent (eventArgument);
  1205. }
  1206. // TODO: This is prolly obsolete
  1207. protected virtual void RaisePostBackEvent (string eventArgument)
  1208. {
  1209. int i = eventArgument.IndexOf ('$');
  1210. if (i != -1)
  1211. ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
  1212. else
  1213. ProcessEvent (eventArgument, null);
  1214. }
  1215. void ProcessEvent (string eventName, string param)
  1216. {
  1217. switch (eventName)
  1218. {
  1219. case DataControlCommands.PageCommandName:
  1220. int newIndex = -1;
  1221. switch (param) {
  1222. case DataControlCommands.FirstPageCommandArgument:
  1223. newIndex = 0;
  1224. break;
  1225. case DataControlCommands.LastPageCommandArgument:
  1226. newIndex = PageCount - 1;
  1227. break;
  1228. case DataControlCommands.NextPageCommandArgument:
  1229. if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
  1230. break;
  1231. case DataControlCommands.PreviousPageCommandArgument:
  1232. if (PageIndex > 0) newIndex = PageIndex - 1;
  1233. break;
  1234. default:
  1235. newIndex = int.Parse (param) - 1;
  1236. break;
  1237. }
  1238. ShowPage (newIndex);
  1239. break;
  1240. case DataControlCommands.FirstPageCommandArgument:
  1241. ShowPage (0);
  1242. break;
  1243. case DataControlCommands.LastPageCommandArgument:
  1244. ShowPage (PageCount - 1);
  1245. break;
  1246. case DataControlCommands.NextPageCommandArgument:
  1247. if (PageIndex < PageCount - 1)
  1248. ShowPage (PageIndex + 1);
  1249. break;
  1250. case DataControlCommands.PreviousPageCommandArgument:
  1251. if (PageIndex > 0)
  1252. ShowPage (PageIndex - 1);
  1253. break;
  1254. case DataControlCommands.EditCommandName:
  1255. ChangeMode (DetailsViewMode.Edit);
  1256. break;
  1257. case DataControlCommands.NewCommandName:
  1258. ChangeMode (DetailsViewMode.Insert);
  1259. break;
  1260. case DataControlCommands.UpdateCommandName:
  1261. UpdateItem (param, true);
  1262. break;
  1263. case DataControlCommands.CancelCommandName:
  1264. CancelEdit ();
  1265. break;
  1266. case DataControlCommands.DeleteCommandName:
  1267. DeleteItem ();
  1268. break;
  1269. case DataControlCommands.InsertCommandName:
  1270. InsertItem (true);
  1271. break;
  1272. }
  1273. }
  1274. void ShowPage (int newIndex)
  1275. {
  1276. DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
  1277. OnPageIndexChanging (args);
  1278. if (!args.Cancel) {
  1279. if (args.NewPageIndex < 0 || args.NewPageIndex >= PageCount)
  1280. return;
  1281. EndRowEdit (false);
  1282. PageIndex = args.NewPageIndex;
  1283. OnPageIndexChanged (EventArgs.Empty);
  1284. }
  1285. }
  1286. public void ChangeMode (DetailsViewMode newMode)
  1287. {
  1288. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
  1289. OnModeChanging (args);
  1290. if (!args.Cancel) {
  1291. CurrentMode = args.NewMode;
  1292. OnModeChanged (EventArgs.Empty);
  1293. RequireBinding ();
  1294. }
  1295. }
  1296. void CancelEdit ()
  1297. {
  1298. DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
  1299. OnModeChanging (args);
  1300. if (!args.Cancel) {
  1301. EndRowEdit ();
  1302. }
  1303. }
  1304. public virtual void UpdateItem (bool causesValidation)
  1305. {
  1306. UpdateItem (null, causesValidation);
  1307. }
  1308. void UpdateItem (string param, bool causesValidation)
  1309. {
  1310. if (causesValidation)
  1311. Page.Validate ();
  1312. if (CurrentMode != DetailsViewMode.Edit) throw new NotSupportedException ();
  1313. currentEditOldValues = oldEditValues.Values;
  1314. currentEditRowKeys = DataKey.Values;
  1315. currentEditNewValues = GetRowValues (false, false);
  1316. DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1317. OnItemUpdating (args);
  1318. if (!args.Cancel) {
  1319. DataSourceView view = GetData ();
  1320. if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
  1321. view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
  1322. } else
  1323. EndRowEdit ();
  1324. }
  1325. bool UpdateCallback (int recordsAffected, Exception exception)
  1326. {
  1327. DetailsViewUpdatedEventArgs dargs = new DetailsViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1328. OnItemUpdated (dargs);
  1329. if (!dargs.KeepInEditMode)
  1330. EndRowEdit ();
  1331. return dargs.ExceptionHandled;
  1332. }
  1333. public virtual void InsertItem (bool causesValidation)
  1334. {
  1335. InsertItem (null, causesValidation);
  1336. }
  1337. void InsertItem (string param, bool causesValidation)
  1338. {
  1339. if (causesValidation)
  1340. Page.Validate ();
  1341. if (CurrentMode != DetailsViewMode.Insert) throw new NotSupportedException ();
  1342. currentEditNewValues = GetRowValues (false, true);
  1343. DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
  1344. OnItemInserting (args);
  1345. if (!args.Cancel) {
  1346. DataSourceView view = GetData ();
  1347. if (view == null)
  1348. return;
  1349. view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
  1350. } else
  1351. EndRowEdit ();
  1352. }
  1353. bool InsertCallback (int recordsAffected, Exception exception)
  1354. {
  1355. DetailsViewInsertedEventArgs dargs = new DetailsViewInsertedEventArgs (recordsAffected, exception, currentEditNewValues);
  1356. OnItemInserted (dargs);
  1357. if (!dargs.KeepInInsertMode)
  1358. EndRowEdit ();
  1359. return dargs.ExceptionHandled;
  1360. }
  1361. public virtual void DeleteItem ()
  1362. {
  1363. currentEditRowKeys = DataKey == null ? null : DataKey.Values;
  1364. currentEditNewValues = GetRowValues (true, true);
  1365. DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
  1366. OnItemDeleting (args);
  1367. if (!args.Cancel) {
  1368. if (PageIndex == PageCount - 1)
  1369. PageIndex --;
  1370. RequireBinding ();
  1371. DataSourceView view = GetData ();
  1372. if (view != null)
  1373. view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
  1374. else {
  1375. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
  1376. OnItemDeleted (dargs);
  1377. }
  1378. }
  1379. }
  1380. bool DeleteCallback (int recordsAffected, Exception exception)
  1381. {
  1382. DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
  1383. OnItemDeleted (dargs);
  1384. return dargs.ExceptionHandled;
  1385. }
  1386. void EndRowEdit ()
  1387. {
  1388. EndRowEdit (true);
  1389. }
  1390. void EndRowEdit (bool switchToDefaultMode) {
  1391. if (switchToDefaultMode)
  1392. ChangeMode (DefaultMode);
  1393. oldEditValues = new DataKey (new OrderedDictionary ());
  1394. currentEditRowKeys = null;
  1395. currentEditOldValues = null;
  1396. currentEditNewValues = null;
  1397. RequireBinding ();
  1398. }
  1399. protected internal override void LoadControlState (object ob)
  1400. {
  1401. if (ob == null) return;
  1402. object[] state = (object[]) ob;
  1403. base.LoadControlState (state[0]);
  1404. pageIndex = (int) state[1];
  1405. pageCount = (int) state[2];
  1406. CurrentMode = (DetailsViewMode) state[3];
  1407. dataKeyNames = (string[]) state[4];
  1408. defaultMode = (DetailsViewMode) state[5];
  1409. }
  1410. protected internal override object SaveControlState ()
  1411. {
  1412. object bstate = base.SaveControlState ();
  1413. return new object[] {
  1414. bstate, pageIndex, pageCount, CurrentMode, dataKeyNames, defaultMode
  1415. };
  1416. }
  1417. protected override void TrackViewState()
  1418. {
  1419. base.TrackViewState();
  1420. if (columns != null) ((IStateManager)columns).TrackViewState();
  1421. if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
  1422. if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
  1423. if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
  1424. if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
  1425. if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
  1426. if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
  1427. if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
  1428. if (insertRowStyle != null) ((IStateManager)insertRowStyle).TrackViewState();
  1429. if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
  1430. if (key != null) ((IStateManager)key).TrackViewState();
  1431. if (autoFieldProperties != null) {
  1432. foreach (IStateManager sm in autoFieldProperties)
  1433. sm.TrackViewState ();
  1434. }
  1435. }
  1436. protected override object SaveViewState()
  1437. {
  1438. object[] states = new object [14];
  1439. states[0] = base.SaveViewState();
  1440. states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
  1441. states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
  1442. states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
  1443. states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
  1444. states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
  1445. states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
  1446. states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
  1447. states[8] = (insertRowStyle == null ? null : ((IStateManager)insertRowStyle).SaveViewState());
  1448. states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
  1449. states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
  1450. states[11] = (key == null ? null : ((IStateManager)key).SaveViewState());
  1451. states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
  1452. if (autoFieldProperties != null) {
  1453. object[] data = new object [autoFieldProperties.Length];
  1454. bool allNull = true;
  1455. for (int n=0; n<data.Length; n++) {
  1456. data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
  1457. if (data [n] != null) allNull = false;
  1458. }
  1459. if (!allNull) states [13] = data;
  1460. }
  1461. for (int i = states.Length - 1; i >= 0; i--) {
  1462. if (states [i] != null)
  1463. return states;
  1464. }
  1465. return null;
  1466. }
  1467. protected override void LoadViewState (object savedState)
  1468. {
  1469. if (savedState == null) {
  1470. base.LoadViewState (null);
  1471. return;
  1472. }
  1473. object [] states = (object []) savedState;
  1474. if (states[13] != null) {
  1475. object[] data = (object[]) states [13];
  1476. autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
  1477. for (int n=0; n<data.Length; n++) {
  1478. IStateManager p = new AutoGeneratedFieldProperties ();
  1479. p.TrackViewState ();
  1480. p.LoadViewState (data [n]);
  1481. autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
  1482. }
  1483. }
  1484. base.LoadViewState (states[0]);
  1485. EnsureChildControls ();
  1486. if (states[1] != null) ((IStateManager)Fields).LoadViewState (states[1]);
  1487. if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
  1488. if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
  1489. if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
  1490. if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
  1491. if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
  1492. if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
  1493. if (states[8] != null) ((IStateManager)InsertRowStyle).LoadViewState (states[8]);
  1494. if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
  1495. if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
  1496. if (states[11] != null) ((IStateManager)DataKey).LoadViewState (states[11]);
  1497. if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
  1498. }
  1499. void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
  1500. {
  1501. RaiseCallbackEvent (eventArgs);
  1502. }
  1503. protected virtual void RaiseCallbackEvent (string eventArgs)
  1504. {
  1505. string[] clientData = eventArgs.Split ('|');
  1506. PageIndex = int.Parse (clientData[0]);
  1507. RaisePostBackEvent (clientData[1]);
  1508. DataBind ();
  1509. }
  1510. string ICallbackEventHandler.GetCallbackResult ()
  1511. {
  1512. return GetCallbackResult ();
  1513. }
  1514. protected virtual string GetCallbackResult ()
  1515. {
  1516. PrepareControlHierarchy ();
  1517. StringWriter sw = new StringWriter ();
  1518. sw.Write (PageIndex.ToString () + '|');
  1519. HtmlTextWriter writer = new HtmlTextWriter (sw);
  1520. RenderGrid (writer);
  1521. return sw.ToString ();
  1522. }
  1523. [MonoTODO]
  1524. protected virtual string GetCallbackScript (IButtonControl buttonControl, string argument)
  1525. {
  1526. throw new NotImplementedException ();
  1527. }
  1528. string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
  1529. {
  1530. if (EnablePagingCallbacks)
  1531. return "javascript:DetailsView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
  1532. else
  1533. return null;
  1534. }
  1535. protected override void OnPagePreLoad (object sender, EventArgs e)
  1536. {
  1537. base.OnPagePreLoad (sender, e);
  1538. if (Page.IsPostBack && EnablePagingCallbacks) {
  1539. int page;
  1540. if (int.TryParse (Page.Request.Form [ClientID + "_Page"], out page))
  1541. PageIndex = page;
  1542. }
  1543. }
  1544. protected internal override void OnPreRender (EventArgs e)
  1545. {
  1546. base.OnPreRender (e);
  1547. if (EnablePagingCallbacks)
  1548. {
  1549. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(DetailsView), "DetailsView.js")) {
  1550. string url = Page.ClientScript.GetWebResourceUrl (typeof(DetailsView), "DetailsView.js");
  1551. Page.ClientScript.RegisterClientScriptInclude (typeof(DetailsView), "DetailsView.js", url);
  1552. }
  1553. Page.ClientScript.RegisterHiddenField (ClientID + "_Page", PageIndex.ToString ());
  1554. string cgrid = ClientID + "_data";
  1555. string script = string.Format ("var {0} = new Object ();\n", cgrid);
  1556. script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
  1557. script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
  1558. Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
  1559. // Make sure the basic script infrastructure is rendered
  1560. Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
  1561. Page.ClientScript.GetPostBackClientHyperlink (this, "");
  1562. }
  1563. }
  1564. protected internal override void Render (HtmlTextWriter writer)
  1565. {
  1566. PrepareControlHierarchy ();
  1567. if (EnablePagingCallbacks)
  1568. base.RenderBeginTag (writer);
  1569. else
  1570. writer.RenderBeginTag (HtmlTextWriterTag.Div);
  1571. RenderGrid (writer);
  1572. if (EnablePagingCallbacks)
  1573. base.RenderEndTag (writer);
  1574. else
  1575. writer.RenderEndTag ();
  1576. }
  1577. void RenderGrid (HtmlTextWriter writer)
  1578. {
  1579. if (table == null)
  1580. return;
  1581. table.Render (writer);
  1582. }
  1583. [MonoTODO]
  1584. PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
  1585. {
  1586. PostBackOptions pbo = new PostBackOptions (this, control.CommandName + "$" + control.CommandArgument);
  1587. return pbo;
  1588. }
  1589. }
  1590. }
  1591. #endif