GridView.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. //
  2. // System.Web.UI.WebControls.GridView.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. [DesignerAttribute ("System.Web.UI.Design.WebControls.GridViewDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
  41. [ControlValuePropertyAttribute ("SelectedValue")]
  42. [DefaultEventAttribute ("SelectedIndexChanged")]
  43. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  44. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  45. public class GridView: CompositeDataBoundControl, IPostBackEventHandler, ICallbackEventHandler, ICallbackContainer, IPostBackContainer
  46. {
  47. Table table;
  48. GridViewRowCollection rows;
  49. GridViewRow headerRow;
  50. GridViewRow footerRow;
  51. GridViewRow bottomPagerRow;
  52. GridViewRow topPagerRow;
  53. IOrderedDictionary currentEditRowKeys;
  54. IOrderedDictionary currentEditNewValues;
  55. IOrderedDictionary currentEditOldValues;
  56. ITemplate pagerTemplate;
  57. ITemplate emptyDataTemplate;
  58. // View state
  59. DataControlFieldCollection columns;
  60. PagerSettings pagerSettings;
  61. TableItemStyle alternatingRowStyle;
  62. TableItemStyle editRowStyle;
  63. TableItemStyle emptyDataRowStyle;
  64. TableItemStyle footerStyle;
  65. TableItemStyle headerStyle;
  66. TableItemStyle pagerStyle;
  67. TableItemStyle rowStyle;
  68. TableItemStyle selectedRowStyle;
  69. DataKeyArray keys;
  70. DataKey oldEditValues;
  71. AutoGeneratedFieldProperties[] autoFieldProperties;
  72. private static readonly object PageIndexChangedEvent = new object();
  73. private static readonly object PageIndexChangingEvent = new object();
  74. private static readonly object RowCancelingEditEvent = new object();
  75. private static readonly object RowCommandEvent = new object();
  76. private static readonly object RowCreatedEvent = new object();
  77. private static readonly object RowDataBoundEvent = new object();
  78. private static readonly object RowDeletedEvent = new object();
  79. private static readonly object RowDeletingEvent = new object();
  80. private static readonly object RowEditingEvent = new object();
  81. private static readonly object RowUpdatedEvent = new object();
  82. private static readonly object RowUpdatingEvent = new object();
  83. private static readonly object SelectedIndexChangedEvent = new object();
  84. private static readonly object SelectedIndexChangingEvent = new object();
  85. private static readonly object SortedEvent = new object();
  86. private static readonly object SortingEvent = new object();
  87. // Control state
  88. int pageIndex;
  89. int pageCount = -1;
  90. int selectedIndex = -1;
  91. int editIndex = -1;
  92. SortDirection sortDirection = SortDirection.Ascending;
  93. string sortExpression;
  94. public GridView ()
  95. {
  96. }
  97. public event EventHandler PageIndexChanged {
  98. add { Events.AddHandler (PageIndexChangedEvent, value); }
  99. remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
  100. }
  101. public event GridViewPageEventHandler PageIndexChanging {
  102. add { Events.AddHandler (PageIndexChangingEvent, value); }
  103. remove { Events.RemoveHandler (PageIndexChangingEvent, value); }
  104. }
  105. public event GridViewCancelEditEventHandler RowCancelingEdit {
  106. add { Events.AddHandler (RowCancelingEditEvent, value); }
  107. remove { Events.RemoveHandler (RowCancelingEditEvent, value); }
  108. }
  109. public event GridViewCommandEventHandler RowCommand {
  110. add { Events.AddHandler (RowCommandEvent, value); }
  111. remove { Events.RemoveHandler (RowCommandEvent, value); }
  112. }
  113. public event GridViewRowEventHandler RowCreated {
  114. add { Events.AddHandler (RowCreatedEvent, value); }
  115. remove { Events.RemoveHandler (RowCreatedEvent, value); }
  116. }
  117. public event GridViewRowEventHandler RowDataBound {
  118. add { Events.AddHandler (RowDataBoundEvent, value); }
  119. remove { Events.RemoveHandler (RowDataBoundEvent, value); }
  120. }
  121. public event GridViewDeletedEventHandler RowDeleted {
  122. add { Events.AddHandler (RowDeletedEvent, value); }
  123. remove { Events.RemoveHandler (RowDeletedEvent, value); }
  124. }
  125. public event GridViewDeleteEventHandler RowDeleting {
  126. add { Events.AddHandler (RowDeletingEvent, value); }
  127. remove { Events.RemoveHandler (RowDeletingEvent, value); }
  128. }
  129. public event GridViewEditEventHandler RowEditing {
  130. add { Events.AddHandler (RowEditingEvent, value); }
  131. remove { Events.RemoveHandler (RowEditingEvent, value); }
  132. }
  133. public event GridViewUpdatedEventHandler RowUpdated {
  134. add { Events.AddHandler (RowUpdatedEvent, value); }
  135. remove { Events.RemoveHandler (RowUpdatedEvent, value); }
  136. }
  137. public event GridViewUpdateEventHandler RowUpdating {
  138. add { Events.AddHandler (RowUpdatingEvent, value); }
  139. remove { Events.RemoveHandler (RowUpdatingEvent, value); }
  140. }
  141. public event EventHandler SelectedIndexChanged {
  142. add { Events.AddHandler (SelectedIndexChangedEvent, value); }
  143. remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
  144. }
  145. public event GridViewSelectEventHandler SelectedIndexChanging {
  146. add { Events.AddHandler (SelectedIndexChangingEvent, value); }
  147. remove { Events.RemoveHandler (SelectedIndexChangingEvent, value); }
  148. }
  149. public event EventHandler Sorted {
  150. add { Events.AddHandler (SortedEvent, value); }
  151. remove { Events.RemoveHandler (SortedEvent, value); }
  152. }
  153. public event GridViewSortEventHandler Sorting {
  154. add { Events.AddHandler (SortingEvent, value); }
  155. remove { Events.RemoveHandler (SortingEvent, value); }
  156. }
  157. protected virtual void OnPageIndexChanged (EventArgs e)
  158. {
  159. if (Events != null) {
  160. EventHandler eh = (EventHandler) Events [PageIndexChangedEvent];
  161. if (eh != null) eh (this, e);
  162. }
  163. }
  164. protected virtual void OnPageIndexChanging (GridViewPageEventArgs e)
  165. {
  166. if (Events != null) {
  167. GridViewPageEventHandler eh = (GridViewPageEventHandler) Events [PageIndexChangingEvent];
  168. if (eh != null) eh (this, e);
  169. }
  170. }
  171. protected virtual void OnRowCancelingEdit (GridViewCancelEditEventArgs e)
  172. {
  173. if (Events != null) {
  174. GridViewCancelEditEventHandler eh = (GridViewCancelEditEventHandler) Events [RowCancelingEditEvent];
  175. if (eh != null) eh (this, e);
  176. }
  177. }
  178. protected virtual void OnRowCommand (GridViewCommandEventArgs e)
  179. {
  180. if (Events != null) {
  181. GridViewCommandEventHandler eh = (GridViewCommandEventHandler) Events [RowCommandEvent];
  182. if (eh != null) eh (this, e);
  183. }
  184. }
  185. protected virtual void OnRowCreated (GridViewRowEventArgs e)
  186. {
  187. if (Events != null) {
  188. GridViewRowEventHandler eh = (GridViewRowEventHandler) Events [RowCreatedEvent];
  189. if (eh != null) eh (this, e);
  190. }
  191. }
  192. protected virtual void OnRowDataBound (GridViewRowEventArgs e)
  193. {
  194. if (Events != null) {
  195. GridViewRowEventHandler eh = (GridViewRowEventHandler) Events [RowDataBoundEvent];
  196. if (eh != null) eh (this, e);
  197. }
  198. }
  199. protected virtual void OnRowDeleted (GridViewDeletedEventArgs e)
  200. {
  201. if (Events != null) {
  202. GridViewDeletedEventHandler eh = (GridViewDeletedEventHandler) Events [RowDeletedEvent];
  203. if (eh != null) eh (this, e);
  204. }
  205. }
  206. protected virtual void OnRowDeleting (GridViewDeleteEventArgs e)
  207. {
  208. if (Events != null) {
  209. GridViewDeleteEventHandler eh = (GridViewDeleteEventHandler) Events [RowDeletingEvent];
  210. if (eh != null) eh (this, e);
  211. }
  212. }
  213. protected virtual void OnRowEditing (GridViewEditEventArgs e)
  214. {
  215. if (Events != null) {
  216. GridViewEditEventHandler eh = (GridViewEditEventHandler) Events [RowEditingEvent];
  217. if (eh != null) eh (this, e);
  218. }
  219. }
  220. protected virtual void OnRowUpdated (GridViewUpdatedEventArgs e)
  221. {
  222. if (Events != null) {
  223. GridViewUpdatedEventHandler eh = (GridViewUpdatedEventHandler) Events [RowUpdatedEvent];
  224. if (eh != null) eh (this, e);
  225. }
  226. }
  227. protected virtual void OnRowUpdating (GridViewUpdateEventArgs e)
  228. {
  229. if (Events != null) {
  230. GridViewUpdateEventHandler eh = (GridViewUpdateEventHandler) Events [RowUpdatingEvent];
  231. if (eh != null) eh (this, e);
  232. }
  233. }
  234. protected virtual void OnSelectedIndexChanged (EventArgs e)
  235. {
  236. if (Events != null) {
  237. EventHandler eh = (EventHandler) Events [SelectedIndexChangedEvent];
  238. if (eh != null) eh (this, e);
  239. }
  240. }
  241. protected virtual void OnSelectedIndexChanging (GridViewSelectEventArgs e)
  242. {
  243. if (Events != null) {
  244. GridViewSelectEventHandler eh = (GridViewSelectEventHandler) Events [SelectedIndexChangingEvent];
  245. if (eh != null) eh (this, e);
  246. }
  247. }
  248. protected virtual void OnSorted (EventArgs e)
  249. {
  250. if (Events != null) {
  251. EventHandler eh = (EventHandler) Events [SortedEvent];
  252. if (eh != null) eh (this, e);
  253. }
  254. }
  255. protected virtual void OnSorting (GridViewSortEventArgs e)
  256. {
  257. if (Events != null) {
  258. GridViewSortEventHandler eh = (GridViewSortEventHandler) Events [SortingEvent];
  259. if (eh != null) eh (this, e);
  260. }
  261. }
  262. [WebCategoryAttribute ("Paging")]
  263. [DefaultValueAttribute (false)]
  264. public bool AllowPaging {
  265. get {
  266. object ob = ViewState ["AllowPaging"];
  267. if (ob != null) return (bool) ob;
  268. return false;
  269. }
  270. set {
  271. ViewState ["AllowPaging"] = value;
  272. RequireBinding ();
  273. }
  274. }
  275. [WebCategoryAttribute ("Behavior")]
  276. [DefaultValueAttribute (false)]
  277. public bool AllowSorting {
  278. get {
  279. object ob = ViewState ["AllowSorting"];
  280. if (ob != null) return (bool) ob;
  281. return false;
  282. }
  283. set {
  284. ViewState ["AllowSorting"] = value;
  285. RequireBinding ();
  286. }
  287. }
  288. [WebCategoryAttribute ("Styles")]
  289. [PersistenceMode (PersistenceMode.InnerProperty)]
  290. [NotifyParentProperty (true)]
  291. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  292. public virtual TableItemStyle AlternatingRowStyle {
  293. get {
  294. if (alternatingRowStyle == null) {
  295. alternatingRowStyle = new TableItemStyle ();
  296. if (IsTrackingViewState)
  297. alternatingRowStyle.TrackViewState();
  298. }
  299. return alternatingRowStyle;
  300. }
  301. }
  302. [WebCategoryAttribute ("Behavior")]
  303. [DefaultValueAttribute (false)]
  304. public virtual bool AutoGenerateEditButton {
  305. get {
  306. object ob = ViewState ["AutoGenerateEditButton"];
  307. if (ob != null) return (bool) ob;
  308. return false;
  309. }
  310. set {
  311. ViewState ["AutoGenerateEditButton"] = value;
  312. RequireBinding ();
  313. }
  314. }
  315. [WebCategoryAttribute ("Behavior")]
  316. [DefaultValueAttribute (false)]
  317. public virtual bool AutoGenerateDeleteButton {
  318. get {
  319. object ob = ViewState ["AutoGenerateDeleteButton"];
  320. if (ob != null) return (bool) ob;
  321. return false;
  322. }
  323. set {
  324. ViewState ["AutoGenerateDeleteButton"] = value;
  325. RequireBinding ();
  326. }
  327. }
  328. [WebCategoryAttribute ("Behavior")]
  329. [DefaultValueAttribute (false)]
  330. public virtual bool AutoGenerateSelectButton {
  331. get {
  332. object ob = ViewState ["AutoGenerateSelectButton"];
  333. if (ob != null) return (bool) ob;
  334. return false;
  335. }
  336. set {
  337. ViewState ["AutoGenerateSelectButton"] = value;
  338. RequireBinding ();
  339. }
  340. }
  341. [WebCategoryAttribute ("Behavior")]
  342. [DefaultValueAttribute (true)]
  343. public virtual bool AutoGenerateColumns {
  344. get {
  345. object ob = ViewState ["AutoGenerateColumns"];
  346. if (ob != null) return (bool) ob;
  347. return true;
  348. }
  349. set {
  350. ViewState ["AutoGenerateColumns"] = value;
  351. RequireBinding ();
  352. }
  353. }
  354. [UrlPropertyAttribute]
  355. [WebCategoryAttribute ("Appearance")]
  356. [DefaultValueAttribute ("")]
  357. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  358. public virtual string BackImageUrl {
  359. get {
  360. object ob = ViewState ["BackImageUrl"];
  361. if (ob != null) return (string) ob;
  362. return string.Empty;
  363. }
  364. set {
  365. ViewState ["BackImageUrl"] = value;
  366. RequireBinding ();
  367. }
  368. }
  369. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  370. [BrowsableAttribute (false)]
  371. public virtual GridViewRow BottomPagerRow {
  372. get {
  373. EnsureDataBound ();
  374. return bottomPagerRow;
  375. }
  376. }
  377. [WebCategoryAttribute ("Accessibility")]
  378. [DefaultValueAttribute ("")]
  379. [LocalizableAttribute (true)]
  380. public string Caption {
  381. get {
  382. object ob = ViewState ["Caption"];
  383. if (ob != null) return (string) ob;
  384. return string.Empty;
  385. }
  386. set {
  387. ViewState ["Caption"] = value;
  388. RequireBinding ();
  389. }
  390. }
  391. [WebCategoryAttribute ("Accessibility")]
  392. [DefaultValueAttribute (TableCaptionAlign.NotSet)]
  393. public virtual TableCaptionAlign CaptionAlign
  394. {
  395. get {
  396. object o = ViewState ["CaptionAlign"];
  397. if(o != null) return (TableCaptionAlign) o;
  398. return TableCaptionAlign.NotSet;
  399. }
  400. set {
  401. ViewState ["CaptionAlign"] = value;
  402. RequireBinding ();
  403. }
  404. }
  405. [WebCategoryAttribute ("Layout")]
  406. [DefaultValueAttribute (-1)]
  407. public virtual int CellPadding
  408. {
  409. get {
  410. object o = ViewState ["CellPadding"];
  411. if (o != null) return (int) o;
  412. return -1;
  413. }
  414. set {
  415. ViewState ["CellPadding"] = value;
  416. RequireBinding ();
  417. }
  418. }
  419. [WebCategoryAttribute ("Layout")]
  420. [DefaultValueAttribute (0)]
  421. public virtual int CellSpacing
  422. {
  423. get {
  424. object o = ViewState ["CellSpacing"];
  425. if (o != null) return (int) o;
  426. return 0;
  427. }
  428. set {
  429. ViewState ["CellSpacing"] = value;
  430. RequireBinding ();
  431. }
  432. }
  433. [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  434. [MergablePropertyAttribute (false)]
  435. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  436. [DefaultValueAttribute (null)]
  437. [WebCategoryAttribute ("Misc")]
  438. public virtual DataControlFieldCollection Columns {
  439. get {
  440. if (columns == null) {
  441. columns = new DataControlFieldCollection ();
  442. columns.FieldsChanged += new EventHandler (OnFieldsChanged);
  443. if (IsTrackingViewState)
  444. ((IStateManager)columns).TrackViewState ();
  445. }
  446. return columns;
  447. }
  448. }
  449. [DefaultValueAttribute (null)]
  450. [WebCategoryAttribute ("Data")]
  451. [TypeConverter (typeof(StringArrayConverter))]
  452. [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
  453. public virtual string[] DataKeyNames
  454. {
  455. get {
  456. object o = ViewState ["DataKeyNames"];
  457. if (o != null) return (string[]) o;
  458. return null;
  459. }
  460. set {
  461. ViewState ["DataKeyNames"] = value;
  462. RequireBinding ();
  463. }
  464. }
  465. [BrowsableAttribute (false)]
  466. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  467. public virtual DataKeyArray DataKeys {
  468. get {
  469. EnsureDataBound ();
  470. return keys;
  471. }
  472. }
  473. [WebCategoryAttribute ("Misc")]
  474. [DefaultValueAttribute (-1)]
  475. public int EditIndex {
  476. get {
  477. return editIndex;
  478. }
  479. set {
  480. editIndex = value;
  481. RequireBinding ();
  482. }
  483. }
  484. [WebCategoryAttribute ("Styles")]
  485. [PersistenceMode (PersistenceMode.InnerProperty)]
  486. [NotifyParentProperty (true)]
  487. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  488. public virtual TableItemStyle EditRowStyle {
  489. get {
  490. if (editRowStyle == null) {
  491. editRowStyle = new TableItemStyle ();
  492. if (IsTrackingViewState)
  493. editRowStyle.TrackViewState();
  494. }
  495. return editRowStyle;
  496. }
  497. }
  498. [WebCategoryAttribute ("Styles")]
  499. [PersistenceMode (PersistenceMode.InnerProperty)]
  500. [NotifyParentProperty (true)]
  501. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  502. public virtual TableItemStyle EmptyDataRowStyle {
  503. get {
  504. if (emptyDataRowStyle == null) {
  505. emptyDataRowStyle = new TableItemStyle ();
  506. if (IsTrackingViewState)
  507. emptyDataRowStyle.TrackViewState();
  508. }
  509. return emptyDataRowStyle;
  510. }
  511. }
  512. [DefaultValue (null)]
  513. [TemplateContainer (typeof(GridView), BindingDirection.OneWay)]
  514. [PersistenceMode (PersistenceMode.InnerProperty)]
  515. [Browsable (false)]
  516. public ITemplate EmptyDataTemplate {
  517. get { return emptyDataTemplate; }
  518. set { emptyDataTemplate = value; RequireBinding (); }
  519. }
  520. [LocalizableAttribute (true)]
  521. [WebCategoryAttribute ("Appearance")]
  522. [DefaultValueAttribute ("")]
  523. public virtual string EmptyDataText {
  524. get {
  525. object ob = ViewState ["EmptyDataText"];
  526. if (ob != null) return (string) ob;
  527. return string.Empty;
  528. }
  529. set {
  530. ViewState ["EmptyDataText"] = value;
  531. RequireBinding ();
  532. }
  533. }
  534. [WebCategoryAttribute ("Behavior")]
  535. [DefaultValueAttribute (false)]
  536. public virtual bool EnableSortingAndPagingCallbacks {
  537. get {
  538. object ob = ViewState ["EnableSortingAndPagingCallbacks"];
  539. if (ob != null) return (bool) ob;
  540. return false;
  541. }
  542. set {
  543. ViewState ["EnableSortingAndPagingCallbacks"] = value;
  544. RequireBinding ();
  545. }
  546. }
  547. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  548. [BrowsableAttribute (false)]
  549. public virtual GridViewRow FooterRow {
  550. get {
  551. if (footerRow == null)
  552. footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
  553. return footerRow;
  554. }
  555. }
  556. [WebCategoryAttribute ("Styles")]
  557. [PersistenceMode (PersistenceMode.InnerProperty)]
  558. [NotifyParentProperty (true)]
  559. [DefaultValue (null)]
  560. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  561. public virtual TableItemStyle FooterStyle {
  562. get {
  563. if (footerStyle == null) {
  564. footerStyle = new TableItemStyle ();
  565. if (IsTrackingViewState)
  566. footerStyle.TrackViewState();
  567. }
  568. return footerStyle;
  569. }
  570. }
  571. [WebCategoryAttribute ("Appearance")]
  572. [DefaultValueAttribute (GridLines.Both)]
  573. public virtual GridLines GridLines {
  574. get {
  575. object ob = ViewState ["GridLines"];
  576. if (ob != null) return (GridLines) ob;
  577. return GridLines.Both;
  578. }
  579. set {
  580. ViewState ["GridLines"] = value;
  581. }
  582. }
  583. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  584. [BrowsableAttribute (false)]
  585. public virtual GridViewRow HeaderRow {
  586. get {
  587. if (headerRow == null)
  588. headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
  589. return headerRow;
  590. }
  591. }
  592. [WebCategoryAttribute ("Styles")]
  593. [PersistenceMode (PersistenceMode.InnerProperty)]
  594. [NotifyParentProperty (true)]
  595. [DefaultValue (null)]
  596. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  597. public virtual TableItemStyle HeaderStyle {
  598. get {
  599. if (headerStyle == null) {
  600. headerStyle = new TableItemStyle ();
  601. if (IsTrackingViewState)
  602. headerStyle.TrackViewState();
  603. }
  604. return headerStyle;
  605. }
  606. }
  607. [DefaultValueAttribute (HorizontalAlign.NotSet)]
  608. public virtual HorizontalAlign HorizontalAlign {
  609. get {
  610. object ob = ViewState ["HorizontalAlign"];
  611. if (ob != null) return (HorizontalAlign) ob;
  612. return HorizontalAlign.NotSet;
  613. }
  614. set {
  615. ViewState ["HorizontalAlign"] = value;
  616. RequireBinding ();
  617. }
  618. }
  619. [BrowsableAttribute (false)]
  620. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  621. public int PageCount {
  622. get {
  623. if (pageCount != -1) return pageCount;
  624. EnsureDataBound ();
  625. return pageCount;
  626. }
  627. }
  628. [WebCategoryAttribute ("Paging")]
  629. [BrowsableAttribute (true)]
  630. [DefaultValueAttribute (0)]
  631. public int PageIndex {
  632. get {
  633. return pageIndex;
  634. }
  635. set {
  636. pageIndex = value;
  637. RequireBinding ();
  638. }
  639. }
  640. [DefaultValueAttribute (10)]
  641. [WebCategoryAttribute ("Paging")]
  642. public int PageSize {
  643. get {
  644. object ob = ViewState ["PageSize"];
  645. if (ob != null) return (int) ob;
  646. return 10;
  647. }
  648. set {
  649. ViewState ["PageSize"] = value;
  650. RequireBinding ();
  651. }
  652. }
  653. [WebCategoryAttribute ("Paging")]
  654. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
  655. [NotifyParentPropertyAttribute (true)]
  656. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  657. public PagerSettings PagerSettings {
  658. get {
  659. if (pagerSettings == null) {
  660. pagerSettings = new PagerSettings (this);
  661. if (IsTrackingViewState)
  662. ((IStateManager)pagerSettings).TrackViewState ();
  663. }
  664. return pagerSettings;
  665. }
  666. }
  667. [WebCategoryAttribute ("Styles")]
  668. [PersistenceMode (PersistenceMode.InnerProperty)]
  669. [NotifyParentProperty (true)]
  670. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  671. public virtual TableItemStyle PagerStyle {
  672. get {
  673. if (pagerStyle == null) {
  674. pagerStyle = new TableItemStyle ();
  675. if (IsTrackingViewState)
  676. pagerStyle.TrackViewState();
  677. }
  678. return pagerStyle;
  679. }
  680. }
  681. [DefaultValue (null)]
  682. [TemplateContainer (typeof(GridView), BindingDirection.OneWay)]
  683. [PersistenceMode (PersistenceMode.InnerProperty)]
  684. [Browsable (false)]
  685. public ITemplate PagerTemplate {
  686. get { return pagerTemplate; }
  687. set { pagerTemplate = value; RequireBinding (); }
  688. }
  689. [DefaultValueAttribute ("")]
  690. [WebCategoryAttribute ("Accessibility")]
  691. // [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
  692. public virtual string RowHeaderColumn {
  693. get {
  694. object ob = ViewState ["RowHeaderColumn"];
  695. if (ob != null) return (string) ob;
  696. return string.Empty;
  697. }
  698. set {
  699. ViewState ["RowHeaderColumn"] = value;
  700. RequireBinding ();
  701. }
  702. }
  703. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  704. [BrowsableAttribute (false)]
  705. public virtual GridViewRowCollection Rows {
  706. get {
  707. EnsureDataBound ();
  708. return rows;
  709. }
  710. }
  711. [WebCategoryAttribute ("Styles")]
  712. [PersistenceMode (PersistenceMode.InnerProperty)]
  713. [NotifyParentProperty (true)]
  714. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  715. public virtual TableItemStyle RowStyle {
  716. get {
  717. if (rowStyle == null) {
  718. rowStyle = new TableItemStyle ();
  719. if (IsTrackingViewState)
  720. rowStyle.TrackViewState();
  721. }
  722. return rowStyle;
  723. }
  724. }
  725. [BrowsableAttribute (false)]
  726. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  727. public virtual DataKey SelectedDataKey {
  728. get {
  729. if (selectedIndex >= 0 && selectedIndex < DataKeys.Count) {
  730. return DataKeys [selectedIndex];
  731. } else
  732. return null;
  733. }
  734. }
  735. [BindableAttribute (true)]
  736. [DefaultValueAttribute (-1)]
  737. public int SelectedIndex {
  738. get {
  739. return selectedIndex;
  740. }
  741. set {
  742. if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
  743. int oldIndex = selectedIndex;
  744. selectedIndex = -1;
  745. Rows [oldIndex].RowState = GetRowState (oldIndex);
  746. }
  747. selectedIndex = value;
  748. if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
  749. Rows [selectedIndex].RowState = GetRowState (selectedIndex);
  750. }
  751. }
  752. }
  753. [BrowsableAttribute (false)]
  754. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  755. public virtual GridViewRow SelectedRow {
  756. get {
  757. if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
  758. return Rows [selectedIndex];
  759. } else
  760. return null;
  761. }
  762. }
  763. [WebCategoryAttribute ("Styles")]
  764. [PersistenceMode (PersistenceMode.InnerProperty)]
  765. [NotifyParentProperty (true)]
  766. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  767. public virtual TableItemStyle SelectedRowStyle {
  768. get {
  769. if (selectedRowStyle == null) {
  770. selectedRowStyle = new TableItemStyle ();
  771. if (IsTrackingViewState)
  772. selectedRowStyle.TrackViewState();
  773. }
  774. return selectedRowStyle;
  775. }
  776. }
  777. [BrowsableAttribute (false)]
  778. public virtual object SelectedValue {
  779. get { return SelectedDataKey.Value; }
  780. }
  781. [WebCategoryAttribute ("Appearance")]
  782. [DefaultValueAttribute (false)]
  783. public virtual bool ShowFooter {
  784. get {
  785. object ob = ViewState ["ShowFooter"];
  786. if (ob != null) return (bool) ob;
  787. return false;
  788. }
  789. set {
  790. ViewState ["ShowFooter"] = value;
  791. RequireBinding ();
  792. }
  793. }
  794. [WebCategoryAttribute ("Appearance")]
  795. [DefaultValueAttribute (true)]
  796. public virtual bool ShowHeader {
  797. get {
  798. object ob = ViewState ["ShowHeader"];
  799. if (ob != null) return (bool) ob;
  800. return true;
  801. }
  802. set {
  803. ViewState ["ShowHeader"] = value;
  804. RequireBinding ();
  805. }
  806. }
  807. [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
  808. [BrowsableAttribute (false)]
  809. [DefaultValueAttribute (SortDirection.Ascending)]
  810. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  811. public virtual SortDirection SortDirection {
  812. get { return sortDirection; }
  813. }
  814. [BrowsableAttribute (false)]
  815. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  816. public virtual string SortExpression {
  817. get { return sortExpression; }
  818. }
  819. [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
  820. [BrowsableAttribute (false)]
  821. public virtual GridViewRow TopPagerRow {
  822. get {
  823. EnsureDataBound ();
  824. return topPagerRow;
  825. }
  826. }
  827. [WebCategoryAttribute ("Accessibility")]
  828. [DefaultValueAttribute (true)]
  829. public virtual bool UseAccessibleHeader {
  830. get {
  831. object ob = ViewState ["UseAccessibleHeader"];
  832. if (ob != null) return (bool) ob;
  833. return true;
  834. }
  835. set {
  836. ViewState ["UseAccessibleHeader"] = value;
  837. RequireBinding ();
  838. }
  839. }
  840. public virtual bool IsBindableType (Type type)
  841. {
  842. return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Guid);
  843. }
  844. protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
  845. {
  846. return base.CreateDataSourceSelectArguments ();
  847. }
  848. protected virtual ICollection CreateColumns (PagedDataSource dataSource, bool useDataSource)
  849. {
  850. ArrayList fields = new ArrayList ();
  851. if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateSelectButton) {
  852. CommandField field = new CommandField ();
  853. field.ShowEditButton = AutoGenerateEditButton;
  854. field.ShowDeleteButton = AutoGenerateDeleteButton;
  855. field.ShowSelectButton = AutoGenerateSelectButton;
  856. fields.Add (field);
  857. }
  858. if (AutoGenerateColumns) {
  859. if (useDataSource)
  860. autoFieldProperties = CreateAutoFieldProperties (dataSource);
  861. if (autoFieldProperties != null) {
  862. foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
  863. fields.Add (CreateAutoGeneratedColumn (props));
  864. }
  865. }
  866. fields.AddRange (Columns);
  867. return fields;
  868. }
  869. protected virtual AutoGeneratedField CreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
  870. {
  871. return new AutoGeneratedField (fieldProperties);
  872. }
  873. AutoGeneratedFieldProperties[] CreateAutoFieldProperties (PagedDataSource source)
  874. {
  875. if(source == null) return null;
  876. PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor[0]);
  877. Type prop_type;
  878. ArrayList retVal = new ArrayList();
  879. if (props == null)
  880. {
  881. object fitem = null;
  882. prop_type = null;
  883. PropertyInfo prop_item = source.DataSource.GetType().GetProperty("Item",
  884. BindingFlags.Instance | BindingFlags.Static |
  885. BindingFlags.Public, null, null,
  886. new Type[] { typeof(int) }, null);
  887. if (prop_item != null) {
  888. prop_type = prop_item.PropertyType;
  889. }
  890. if (prop_type == null || prop_type == typeof(object)) {
  891. IEnumerator en = source.GetEnumerator();
  892. if (en.MoveNext())
  893. fitem = en.Current;
  894. if (fitem != null)
  895. prop_type = fitem.GetType();
  896. }
  897. if (fitem != null && fitem is ICustomTypeDescriptor) {
  898. props = TypeDescriptor.GetProperties(fitem);
  899. } else if (prop_type != null) {
  900. if (IsBindableType (prop_type)) {
  901. AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
  902. ((IStateManager)field).TrackViewState();
  903. field.Name = "Item";
  904. field.DataField = BoundField.ThisExpression;
  905. field.Type = prop_type;
  906. retVal.Add (field);
  907. } else {
  908. props = TypeDescriptor.GetProperties (prop_type);
  909. }
  910. }
  911. }
  912. if (props != null && props.Count > 0)
  913. {
  914. foreach (PropertyDescriptor current in props) {
  915. if (IsBindableType (current.PropertyType)) {
  916. AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
  917. ((IStateManager)field).TrackViewState();
  918. field.Name = current.Name;
  919. field.DataField = current.Name;
  920. field.IsReadOnly = current.IsReadOnly;
  921. field.Type = current.PropertyType;
  922. retVal.Add (field);
  923. }
  924. }
  925. }
  926. if (retVal.Count > 0)
  927. return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
  928. throw new HttpException(HttpRuntime.FormatResourceString("DataGrid_NoAutoGenColumns", ID));
  929. }
  930. protected virtual GridViewRow CreateRow (int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState)
  931. {
  932. GridViewRow row = new GridViewRow (rowIndex, dataSourceIndex, rowType, rowState);
  933. OnRowCreated (new GridViewRowEventArgs (row));
  934. return row;
  935. }
  936. void RequireBinding ()
  937. {
  938. if (Initialized) {
  939. RequiresDataBinding = true;
  940. pageCount = -1;
  941. }
  942. }
  943. protected virtual ChildTable CreateChildTable ()
  944. {
  945. ChildTable table = new ChildTable ();
  946. table.Caption = Caption;
  947. table.CaptionAlign = CaptionAlign;
  948. table.CellPadding = CellPadding;
  949. table.CellSpacing = CellSpacing;
  950. table.HorizontalAlign = HorizontalAlign;
  951. table.BackImageUrl = BackImageUrl;
  952. return table;
  953. }
  954. protected override int CreateChildControls (IEnumerable data, bool dataBinding)
  955. {
  956. PagedDataSource dataSource;
  957. if (dataBinding) {
  958. DataSourceView view = GetData ();
  959. dataSource = new PagedDataSource ();
  960. dataSource.DataSource = data;
  961. if (AllowPaging) {
  962. dataSource.AllowPaging = true;
  963. dataSource.PageSize = PageSize;
  964. dataSource.CurrentPageIndex = PageIndex;
  965. if (view.CanPage) {
  966. dataSource.AllowServerPaging = true;
  967. if (view.CanRetrieveTotalRowCount)
  968. dataSource.VirtualCount = SelectArguments.TotalRowCount;
  969. else {
  970. dataSource.DataSourceView = view;
  971. dataSource.DataSourceSelectArguments = SelectArguments;
  972. dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount);
  973. }
  974. }
  975. }
  976. pageCount = dataSource.PageCount;
  977. }
  978. else
  979. {
  980. dataSource = new PagedDataSource ();
  981. dataSource.DataSource = data;
  982. if (AllowPaging) {
  983. dataSource.AllowPaging = true;
  984. dataSource.PageSize = PageSize;
  985. dataSource.CurrentPageIndex = PageIndex;
  986. }
  987. }
  988. bool showPager = AllowPaging && (PageCount > 1);
  989. Controls.Clear ();
  990. table = CreateChildTable ();
  991. Controls.Add (table);
  992. ArrayList list = new ArrayList ();
  993. ArrayList keyList = new ArrayList ();
  994. // Creates the set of fields to show
  995. ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
  996. DataControlField[] fields = new DataControlField [fieldCollection.Count];
  997. fieldCollection.CopyTo (fields, 0);
  998. foreach (DataControlField field in fields)
  999. field.Initialize (AllowSorting, this);
  1000. // Main table creation
  1001. if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
  1002. topPagerRow = CreatePagerRow (fields.Length, dataSource);
  1003. table.Rows.Add (topPagerRow);
  1004. }
  1005. if (ShowHeader) {
  1006. headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
  1007. table.Rows.Add (headerRow);
  1008. InitializeRow (headerRow, fields);
  1009. }
  1010. foreach (object obj in dataSource) {
  1011. DataControlRowState rstate = GetRowState (list.Count);
  1012. GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate);
  1013. row.DataItem = obj;
  1014. list.Add (row);
  1015. table.Rows.Add (row);
  1016. InitializeRow (row, fields);
  1017. if (dataBinding) {
  1018. row.DataBind ();
  1019. OnRowDataBound (new GridViewRowEventArgs (row));
  1020. if (EditIndex == row.RowIndex)
  1021. oldEditValues = new DataKey (GetRowValues (row, false, true));
  1022. keyList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames));
  1023. } else {
  1024. if (EditIndex == row.RowIndex)
  1025. oldEditValues = new DataKey (new OrderedDictionary ());
  1026. keyList.Add (new DataKey (new OrderedDictionary (), DataKeyNames));
  1027. }
  1028. if (list.Count >= PageSize)
  1029. break;
  1030. }
  1031. if (list.Count == 0)
  1032. table.Rows.Add (CreateEmptyrRow (fields.Length));
  1033. if (ShowFooter) {
  1034. footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
  1035. table.Rows.Add (footerRow);
  1036. InitializeRow (footerRow, fields);
  1037. }
  1038. if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
  1039. bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
  1040. table.Rows.Add (bottomPagerRow);
  1041. }
  1042. rows = new GridViewRowCollection (list);
  1043. keys = new DataKeyArray (keyList);
  1044. return dataSource.DataSourceCount;
  1045. }
  1046. DataControlRowState GetRowState (int index)
  1047. {
  1048. DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
  1049. if (index == SelectedIndex) rstate |= DataControlRowState.Selected;
  1050. if (index == EditIndex) rstate |= DataControlRowState.Edit;
  1051. return rstate;
  1052. }
  1053. GridViewRow CreatePagerRow (int fieldCount, PagedDataSource dataSource)
  1054. {
  1055. GridViewRow row = CreateRow (-1, -1, DataControlRowType.Pager, DataControlRowState.Normal);
  1056. InitializePager (row, fieldCount, dataSource);
  1057. return row;
  1058. }
  1059. protected virtual void InitializePager (GridViewRow row, int columnSpan, PagedDataSource dataSource)
  1060. {
  1061. TableCell cell = new TableCell ();
  1062. cell.ColumnSpan = columnSpan;
  1063. if (pagerTemplate != null)
  1064. pagerTemplate.InstantiateIn (cell);
  1065. else
  1066. cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
  1067. row.Cells.Add (cell);
  1068. }
  1069. GridViewRow CreateEmptyrRow (int fieldCount)
  1070. {
  1071. GridViewRow row = CreateRow (-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
  1072. TableCell cell = new TableCell ();
  1073. cell.ColumnSpan = fieldCount;
  1074. if (emptyDataTemplate != null)
  1075. emptyDataTemplate.InstantiateIn (cell);
  1076. else
  1077. cell.Text = EmptyDataText;
  1078. row.Cells.Add (cell);
  1079. return row;
  1080. }
  1081. protected virtual void InitializeRow (GridViewRow row, DataControlField[] fields)
  1082. {
  1083. DataControlCellType ctype;
  1084. bool accessibleHeader = false;
  1085. switch (row.RowType) {
  1086. case DataControlRowType.Header:
  1087. ctype = DataControlCellType.Header;
  1088. accessibleHeader = UseAccessibleHeader;
  1089. break;
  1090. case DataControlRowType.Footer:
  1091. ctype = DataControlCellType.Footer;
  1092. break;
  1093. default:
  1094. ctype = DataControlCellType.DataCell;
  1095. break;
  1096. }
  1097. for (int n=0; n<fields.Length; n++) {
  1098. DataControlField field = fields [n];
  1099. DataControlFieldCell cell;
  1100. if (((field is BoundField) && ((BoundField)field).DataField == RowHeaderColumn) || accessibleHeader)
  1101. cell = new DataControlFieldHeaderCell (field, accessibleHeader ? TableHeaderScope.Column : TableHeaderScope.Row);
  1102. else
  1103. cell = new DataControlFieldCell (field);
  1104. row.Cells.Add (cell);
  1105. field.InitializeCell (cell, ctype, row.RowState, row.RowIndex);
  1106. }
  1107. }
  1108. IOrderedDictionary CreateRowDataKey (GridViewRow row)
  1109. {
  1110. OrderedDictionary dic = new OrderedDictionary ();
  1111. ICustomTypeDescriptor desc = row.DataItem as ICustomTypeDescriptor;
  1112. if (desc != null && DataKeyNames != null) {
  1113. PropertyDescriptorCollection props = desc.GetProperties ();
  1114. foreach (string key in DataKeyNames) {
  1115. PropertyDescriptor prop = props [key];
  1116. dic [key] = prop.GetValue (row.DataItem);
  1117. }
  1118. }
  1119. return dic;
  1120. }
  1121. IOrderedDictionary GetRowValues (GridViewRow row, bool includeReadOnlyFields, bool includePrimaryKey)
  1122. {
  1123. OrderedDictionary dic = new OrderedDictionary ();
  1124. ExtractRowValues (dic, row, includeReadOnlyFields, includePrimaryKey);
  1125. return dic;
  1126. }
  1127. protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, GridViewRow row, bool includeReadOnlyFields, bool includePrimaryKey)
  1128. {
  1129. foreach (TableCell cell in row.Cells) {
  1130. DataControlFieldCell c = cell as DataControlFieldCell;
  1131. if (c != null)
  1132. c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
  1133. }
  1134. if (!includePrimaryKey && DataKeyNames != null)
  1135. foreach (string key in DataKeyNames)
  1136. fieldValues.Remove (key);
  1137. }
  1138. protected override HtmlTextWriterTag TagKey {
  1139. get {
  1140. if (EnableSortingAndPagingCallbacks)
  1141. return HtmlTextWriterTag.Div;
  1142. else
  1143. return HtmlTextWriterTag.Table;
  1144. }
  1145. }
  1146. public sealed override void DataBind ()
  1147. {
  1148. DataSourceView view = GetData ();
  1149. if (AllowPaging && view.CanPage) {
  1150. SelectArguments.StartRowIndex = PageIndex * PageSize;
  1151. SelectArguments.MaximumRows = PageSize;
  1152. if (view.CanRetrieveTotalRowCount)
  1153. SelectArguments.RetrieveTotalRowCount = true;
  1154. }
  1155. if (sortExpression != "")
  1156. SelectArguments.SortExpression = sortExpression;
  1157. base.DataBind ();
  1158. }
  1159. protected override void PerformDataBinding (IEnumerable data)
  1160. {
  1161. base.PerformDataBinding (data);
  1162. }
  1163. protected override void OnInit (EventArgs e)
  1164. {
  1165. Page.RegisterRequiresControlState (this);
  1166. base.OnInit (e);
  1167. }
  1168. void OnFieldsChanged (object sender, EventArgs args)
  1169. {
  1170. RequireBinding ();
  1171. }
  1172. protected override void OnDataPropertyChanged ()
  1173. {
  1174. base.OnDataPropertyChanged ();
  1175. RequireBinding ();
  1176. }
  1177. protected override void OnDataSourceViewChanged (object sender, EventArgs e)
  1178. {
  1179. base.OnDataSourceViewChanged (sender, e);
  1180. RequireBinding ();
  1181. }
  1182. protected override bool OnBubbleEvent (object source, EventArgs e)
  1183. {
  1184. GridViewCommandEventArgs args = e as GridViewCommandEventArgs;
  1185. if (args != null)
  1186. OnRowCommand (args);
  1187. return base.OnBubbleEvent (source, e);
  1188. }
  1189. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  1190. {
  1191. RaisePostBackEvent (eventArgument);
  1192. }
  1193. protected virtual void RaisePostBackEvent (string eventArgument)
  1194. {
  1195. int i = eventArgument.IndexOf ('$');
  1196. if (i != -1)
  1197. ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1));
  1198. else
  1199. ProcessEvent (eventArgument, null);
  1200. }
  1201. void ProcessEvent (string eventName, string param)
  1202. {
  1203. switch (eventName)
  1204. {
  1205. case "Page":
  1206. int newIndex = -1;
  1207. switch (param) {
  1208. case "First":
  1209. newIndex = 0;
  1210. break;
  1211. case "Last":
  1212. newIndex = PageCount - 1;
  1213. break;
  1214. case "Next":
  1215. if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
  1216. break;
  1217. case "Prev":
  1218. if (PageIndex > 0) newIndex = PageIndex - 1;
  1219. break;
  1220. default:
  1221. newIndex = int.Parse (param);
  1222. break;
  1223. }
  1224. ShowPage (newIndex);
  1225. break;
  1226. case "Select":
  1227. SelectRow (int.Parse (param));
  1228. break;
  1229. case "Edit":
  1230. EditRow (int.Parse (param));
  1231. break;
  1232. case "Update":
  1233. UpdateRow (EditIndex, true);
  1234. break;
  1235. case "Cancel":
  1236. CancelEdit ();
  1237. break;
  1238. case "Delete":
  1239. DeleteRow (int.Parse (param));
  1240. break;
  1241. case "Sort":
  1242. Sort (param);
  1243. break;
  1244. }
  1245. }
  1246. void Sort (string newSortExpression)
  1247. {
  1248. SortDirection newDirection;
  1249. if (sortExpression == newSortExpression) {
  1250. if (sortDirection == SortDirection.Ascending)
  1251. newDirection = SortDirection.Descending;
  1252. else
  1253. newDirection = SortDirection.Ascending;
  1254. } else
  1255. newDirection = sortDirection;
  1256. Sort (newSortExpression, newDirection);
  1257. }
  1258. public void Sort (string newSortExpression, SortDirection newSortDirection)
  1259. {
  1260. SortDirection newDirection;
  1261. if (sortExpression == newSortExpression) {
  1262. if (sortDirection == SortDirection.Ascending)
  1263. newDirection = SortDirection.Descending;
  1264. else
  1265. newDirection = SortDirection.Ascending;
  1266. } else
  1267. newDirection = sortDirection;
  1268. GridViewSortEventArgs args = new GridViewSortEventArgs (newSortExpression, newDirection);
  1269. OnSorting (args);
  1270. if (args.Cancel) return;
  1271. sortExpression = args.SortExpression;
  1272. sortDirection = args.SortDirection;
  1273. RequireBinding ();
  1274. OnSorted (EventArgs.Empty);
  1275. }
  1276. void SelectRow (int index)
  1277. {
  1278. GridViewSelectEventArgs args = new GridViewSelectEventArgs (index);
  1279. OnSelectedIndexChanging (args);
  1280. if (!args.Cancel) {
  1281. SelectedIndex = args.NewSelectedIndex;
  1282. OnSelectedIndexChanged (EventArgs.Empty);
  1283. }
  1284. }
  1285. void ShowPage (int newIndex)
  1286. {
  1287. GridViewPageEventArgs args = new GridViewPageEventArgs (newIndex);
  1288. OnPageIndexChanging (args);
  1289. if (!args.Cancel) {
  1290. EndRowEdit ();
  1291. PageIndex = args.NewPageIndex;
  1292. OnPageIndexChanged (EventArgs.Empty);
  1293. }
  1294. }
  1295. void EditRow (int index)
  1296. {
  1297. GridViewEditEventArgs args = new GridViewEditEventArgs (index);
  1298. OnRowEditing (args);
  1299. if (!args.Cancel) {
  1300. EditIndex = args.NewEditIndex;
  1301. }
  1302. }
  1303. void CancelEdit ()
  1304. {
  1305. GridViewCancelEditEventArgs args = new GridViewCancelEditEventArgs (EditIndex);
  1306. OnRowCancelingEdit (args);
  1307. if (!args.Cancel) {
  1308. EndRowEdit ();
  1309. }
  1310. }
  1311. [MonoTODO ("Support two-way binding expressions")]
  1312. public virtual void UpdateRow (int rowIndex, bool causesValidation)
  1313. {
  1314. if (causesValidation)
  1315. Page.Validate ();
  1316. if (rowIndex != EditIndex) throw new NotSupportedException ();
  1317. GridViewRow row = Rows [rowIndex];
  1318. currentEditRowKeys = DataKeys [rowIndex].Values;
  1319. currentEditNewValues = GetRowValues (row, false, true);
  1320. currentEditOldValues = oldEditValues.Values;
  1321. GridViewUpdateEventArgs args = new GridViewUpdateEventArgs (EditIndex, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1322. OnRowUpdating (args);
  1323. if (!args.Cancel) {
  1324. DataSourceView view = GetData ();
  1325. if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
  1326. view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
  1327. } else
  1328. EndRowEdit ();
  1329. }
  1330. bool UpdateCallback (int recordsAffected, Exception exception)
  1331. {
  1332. GridViewUpdatedEventArgs dargs = new GridViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
  1333. OnRowUpdated (dargs);
  1334. if (!dargs.KeepInEditMode)
  1335. EndRowEdit ();
  1336. return dargs.ExceptionHandled;
  1337. }
  1338. public void DeleteRow (int rowIndex)
  1339. {
  1340. GridViewRow row = Rows [rowIndex];
  1341. currentEditRowKeys = DataKeys [rowIndex].Values;
  1342. currentEditNewValues = GetRowValues (row, true, true);
  1343. GridViewDeleteEventArgs args = new GridViewDeleteEventArgs (rowIndex, currentEditRowKeys, currentEditNewValues);
  1344. OnRowDeleting (args);
  1345. if (!args.Cancel) {
  1346. DataSourceView view = GetData ();
  1347. if (view != null)
  1348. view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
  1349. else {
  1350. GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
  1351. OnRowDeleted (dargs);
  1352. }
  1353. }
  1354. }
  1355. bool DeleteCallback (int recordsAffected, Exception exception)
  1356. {
  1357. GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
  1358. OnRowDeleted (dargs);
  1359. return dargs.ExceptionHandled;
  1360. }
  1361. void EndRowEdit ()
  1362. {
  1363. EditIndex = -1;
  1364. oldEditValues = new DataKey (new OrderedDictionary ());
  1365. currentEditRowKeys = null;
  1366. currentEditOldValues = null;
  1367. currentEditNewValues = null;
  1368. }
  1369. protected internal override void LoadControlState (object ob)
  1370. {
  1371. if (ob == null) return;
  1372. object[] state = (object[]) ob;
  1373. base.LoadControlState (state[0]);
  1374. pageIndex = (int) state[1];
  1375. pageCount = (int) state[2];
  1376. selectedIndex = (int) state[3];
  1377. editIndex = (int) state[4];
  1378. sortExpression = (string) state[5];
  1379. sortDirection = (SortDirection) state[6];
  1380. }
  1381. protected internal override object SaveControlState ()
  1382. {
  1383. object bstate = base.SaveControlState ();
  1384. return new object[] {
  1385. bstate, pageIndex, pageCount, selectedIndex, editIndex, sortExpression, sortDirection
  1386. };
  1387. }
  1388. protected override void TrackViewState()
  1389. {
  1390. base.TrackViewState();
  1391. if (columns != null) ((IStateManager)columns).TrackViewState();
  1392. if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
  1393. if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
  1394. if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
  1395. if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
  1396. if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
  1397. if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
  1398. if (selectedRowStyle != null) ((IStateManager)selectedRowStyle).TrackViewState();
  1399. if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
  1400. if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
  1401. if (keys != null) ((IStateManager)keys).TrackViewState();
  1402. if (autoFieldProperties != null) {
  1403. foreach (IStateManager sm in autoFieldProperties)
  1404. sm.TrackViewState ();
  1405. }
  1406. }
  1407. protected override object SaveViewState()
  1408. {
  1409. object[] states = new object [14];
  1410. states[0] = base.SaveViewState();
  1411. states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
  1412. states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
  1413. states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
  1414. states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
  1415. states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
  1416. states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
  1417. states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
  1418. states[8] = (selectedRowStyle == null ? null : ((IStateManager)selectedRowStyle).SaveViewState());
  1419. states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
  1420. states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
  1421. states[11] = (keys == null ? null : ((IStateManager)keys).SaveViewState());
  1422. states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
  1423. if (autoFieldProperties != null) {
  1424. object[] data = new object [autoFieldProperties.Length];
  1425. bool allNull = true;
  1426. for (int n=0; n<data.Length; n++) {
  1427. data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
  1428. if (data [n] != null) allNull = false;
  1429. }
  1430. if (!allNull) states [13] = data;
  1431. }
  1432. for (int i = states.Length - 1; i >= 0; i--) {
  1433. if (states [i] != null)
  1434. return states;
  1435. }
  1436. return null;
  1437. }
  1438. protected override void LoadViewState (object savedState)
  1439. {
  1440. if (savedState == null) {
  1441. base.LoadViewState (null);
  1442. return;
  1443. }
  1444. object [] states = (object []) savedState;
  1445. if (states[13] != null) {
  1446. object[] data = (object[]) states [13];
  1447. autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
  1448. for (int n=0; n<data.Length; n++) {
  1449. IStateManager p = new AutoGeneratedFieldProperties ();
  1450. p.TrackViewState ();
  1451. p.LoadViewState (data [n]);
  1452. autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
  1453. }
  1454. }
  1455. base.LoadViewState (states[0]);
  1456. EnsureChildControls ();
  1457. if (states[1] != null) ((IStateManager)Columns).LoadViewState (states[1]);
  1458. if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
  1459. if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
  1460. if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
  1461. if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
  1462. if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
  1463. if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
  1464. if (states[8] != null) ((IStateManager)SelectedRowStyle).LoadViewState (states[8]);
  1465. if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
  1466. if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
  1467. if (states[11] != null) ((IStateManager)DataKeys).LoadViewState (states[11]);
  1468. if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
  1469. }
  1470. string ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
  1471. {
  1472. string[] clientData = eventArgs.Split ('|');
  1473. pageIndex = int.Parse (clientData[0]);
  1474. sortExpression = HttpUtility.UrlDecode (clientData[1]);
  1475. if (sortExpression == "") sortExpression = null;
  1476. RequireBinding ();
  1477. RaisePostBackEvent (clientData[2]);
  1478. EnsureDataBound ();
  1479. StringWriter sw = new StringWriter ();
  1480. sw.Write (PageIndex.ToString() + '|' + SortExpression + '|');
  1481. HtmlTextWriter writer = new HtmlTextWriter (sw);
  1482. RenderGrid (writer);
  1483. return sw.ToString ();
  1484. }
  1485. string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
  1486. {
  1487. if (EnableSortingAndPagingCallbacks)
  1488. return "javascript:GridView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
  1489. else
  1490. return null;
  1491. }
  1492. PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
  1493. {
  1494. return new PostBackOptions (this, control.CommandName + "$" + control.CommandArgument, null, false, true, false, true, false, null);
  1495. }
  1496. protected override void OnPreRender (EventArgs e)
  1497. {
  1498. base.OnPreRender (e);
  1499. if (EnableSortingAndPagingCallbacks)
  1500. {
  1501. if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(GridView), "GridView.js")) {
  1502. string url = Page.ClientScript.GetWebResourceUrl (typeof(GridView), "GridView.js");
  1503. Page.ClientScript.RegisterClientScriptInclude (typeof(GridView), "GridView.js", url);
  1504. }
  1505. string cgrid = ClientID + "_data";
  1506. string script = string.Format ("var {0} = new Object ();\n", cgrid);
  1507. script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
  1508. script += string.Format ("{0}.sortExp = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (SortExpression == null ? "" : SortExpression));
  1509. script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
  1510. Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
  1511. // Make sure the basic script infrastructure is rendered
  1512. Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
  1513. Page.ClientScript.GetPostBackClientHyperlink (this, "");
  1514. }
  1515. }
  1516. protected override void Render (HtmlTextWriter writer)
  1517. {
  1518. if (EnableSortingAndPagingCallbacks)
  1519. base.RenderBeginTag (writer);
  1520. RenderGrid (writer);
  1521. if (EnableSortingAndPagingCallbacks)
  1522. base.RenderEndTag (writer);
  1523. }
  1524. void RenderGrid (HtmlTextWriter writer)
  1525. {
  1526. switch (GridLines) {
  1527. case GridLines.Horizontal:
  1528. writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
  1529. writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
  1530. break;
  1531. case GridLines.Vertical:
  1532. writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
  1533. writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
  1534. break;
  1535. case GridLines.Both:
  1536. writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
  1537. writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
  1538. break;
  1539. default:
  1540. writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
  1541. break;
  1542. }
  1543. writer.AddAttribute (HtmlTextWriterAttribute.Cellspacing, "0");
  1544. writer.AddStyleAttribute (HtmlTextWriterStyle.BorderCollapse, "collapse");
  1545. table.RenderBeginTag (writer);
  1546. foreach (GridViewRow row in table.Rows)
  1547. {
  1548. switch (row.RowType) {
  1549. case DataControlRowType.Header:
  1550. if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
  1551. break;
  1552. case DataControlRowType.Footer:
  1553. if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
  1554. break;
  1555. case DataControlRowType.Pager:
  1556. if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
  1557. break;
  1558. case DataControlRowType.EmptyDataRow:
  1559. if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
  1560. break;
  1561. default:
  1562. if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
  1563. break;
  1564. }
  1565. if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
  1566. alternatingRowStyle.AddAttributesToRender (writer, row);
  1567. if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
  1568. editRowStyle.AddAttributesToRender (writer, row);
  1569. if ((row.RowState & DataControlRowState.Selected) != 0 && selectedRowStyle != null)
  1570. selectedRowStyle.AddAttributesToRender (writer, row);
  1571. row.RenderBeginTag (writer);
  1572. foreach (TableCell cell in row.Cells) {
  1573. DataControlFieldCell fcell = cell as DataControlFieldCell;
  1574. if (fcell != null) {
  1575. Style cellStyle = null;
  1576. switch (row.RowType) {
  1577. case DataControlRowType.Header: cellStyle = fcell.ContainingField.HeaderStyle; break;
  1578. case DataControlRowType.Footer: cellStyle = fcell.ContainingField.FooterStyle; break;
  1579. default: cellStyle = fcell.ContainingField.ItemStyle; break;
  1580. }
  1581. if (cellStyle != null)
  1582. cellStyle.AddAttributesToRender (writer, cell);
  1583. }
  1584. cell.Render (writer);
  1585. }
  1586. row.RenderEndTag (writer);
  1587. }
  1588. table.RenderEndTag (writer);
  1589. }
  1590. }
  1591. }
  1592. #endif