CommandField.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. //
  2. // System.Web.UI.WebControls.CommandField.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.Collections;
  31. using System.Collections.Specialized;
  32. using System.Web.UI;
  33. using System.ComponentModel;
  34. using System.Security.Permissions;
  35. namespace System.Web.UI.WebControls {
  36. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  37. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  38. public class CommandField : ButtonFieldBase
  39. {
  40. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  41. [UrlPropertyAttribute]
  42. [DefaultValueAttribute ("")]
  43. [WebSysDescription ("")]
  44. [WebCategoryAttribute ("Appearance")]
  45. public virtual string CancelImageUrl {
  46. get {
  47. object ob = ViewState ["CancelImageUrl"];
  48. if (ob != null) return (string) ob;
  49. return "";
  50. }
  51. set {
  52. ViewState ["CancelImageUrl"] = value;
  53. OnFieldChanged ();
  54. }
  55. }
  56. [LocalizableAttribute (true)]
  57. [WebSysDescription ("")]
  58. [WebCategoryAttribute ("Appearance")]
  59. public virtual string CancelText {
  60. get {
  61. object ob = ViewState ["CancelText"];
  62. if (ob != null) return (string) ob;
  63. return "Cancel";
  64. }
  65. set {
  66. ViewState ["CancelText"] = value;
  67. OnFieldChanged ();
  68. }
  69. }
  70. [DefaultValueAttribute (true)]
  71. public override bool CausesValidation {
  72. get {
  73. object ob = ViewState ["CausesValidation"];
  74. if (ob != null) return (bool) ob;
  75. return true;
  76. }
  77. set {
  78. ViewState ["CausesValidation"] = value;
  79. OnFieldChanged ();
  80. }
  81. }
  82. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  83. [UrlPropertyAttribute]
  84. [DefaultValueAttribute ("")]
  85. [WebSysDescription ("")]
  86. [WebCategoryAttribute ("Appearance")]
  87. public virtual string DeleteImageUrl {
  88. get {
  89. object ob = ViewState ["DeleteImageUrl"];
  90. if (ob != null) return (string) ob;
  91. return "";
  92. }
  93. set {
  94. ViewState ["DeleteImageUrl"] = value;
  95. OnFieldChanged ();
  96. }
  97. }
  98. [LocalizableAttribute (true)]
  99. [WebSysDescription ("")]
  100. [WebCategoryAttribute ("Appearance")]
  101. public virtual string DeleteText {
  102. get {
  103. object ob = ViewState ["DeleteText"];
  104. if (ob != null) return (string) ob;
  105. return "Delete";
  106. }
  107. set {
  108. ViewState ["DeleteText"] = value;
  109. OnFieldChanged ();
  110. }
  111. }
  112. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  113. [UrlPropertyAttribute]
  114. [DefaultValueAttribute ("")]
  115. [WebSysDescription ("")]
  116. [WebCategoryAttribute ("Appearance")]
  117. public virtual string EditImageUrl {
  118. get {
  119. object ob = ViewState ["EditImageUrl"];
  120. if (ob != null) return (string) ob;
  121. return "";
  122. }
  123. set {
  124. ViewState ["EditImageUrl"] = value;
  125. OnFieldChanged ();
  126. }
  127. }
  128. [LocalizableAttribute (true)]
  129. [WebSysDescription ("")]
  130. [WebCategoryAttribute ("Appearance")]
  131. public virtual string EditText {
  132. get {
  133. object ob = ViewState ["EditText"];
  134. if (ob != null) return (string) ob;
  135. return "Edit";
  136. }
  137. set {
  138. ViewState ["EditText"] = value;
  139. OnFieldChanged ();
  140. }
  141. }
  142. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  143. [UrlPropertyAttribute]
  144. [DefaultValueAttribute ("")]
  145. [WebSysDescription ("")]
  146. [WebCategoryAttribute ("Appearance")]
  147. public virtual string InsertImageUrl {
  148. get {
  149. object ob = ViewState ["InsertImageUrl"];
  150. if (ob != null) return (string) ob;
  151. return "";
  152. }
  153. set {
  154. ViewState ["InsertImageUrl"] = value;
  155. OnFieldChanged ();
  156. }
  157. }
  158. [LocalizableAttribute (true)]
  159. [WebSysDescription ("")]
  160. [WebCategoryAttribute ("Appearance")]
  161. public virtual string InsertText {
  162. get {
  163. object ob = ViewState ["InsertText"];
  164. if (ob != null) return (string) ob;
  165. return "Insert";
  166. }
  167. set {
  168. ViewState ["InsertText"] = value;
  169. OnFieldChanged ();
  170. }
  171. }
  172. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  173. [UrlPropertyAttribute]
  174. [DefaultValueAttribute ("")]
  175. [WebSysDescription ("")]
  176. [WebCategoryAttribute ("Appearance")]
  177. public virtual string NewImageUrl {
  178. get {
  179. object ob = ViewState ["NewImageUrl"];
  180. if (ob != null) return (string) ob;
  181. return "";
  182. }
  183. set {
  184. ViewState ["NewImageUrl"] = value;
  185. OnFieldChanged ();
  186. }
  187. }
  188. [LocalizableAttribute (true)]
  189. [WebSysDescription ("")]
  190. [WebCategoryAttribute ("Appearance")]
  191. public virtual string NewText {
  192. get {
  193. object ob = ViewState ["NewText"];
  194. if (ob != null) return (string) ob;
  195. return "New";
  196. }
  197. set {
  198. ViewState ["NewText"] = value;
  199. OnFieldChanged ();
  200. }
  201. }
  202. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  203. [UrlPropertyAttribute]
  204. [DefaultValueAttribute ("")]
  205. [WebSysDescription ("")]
  206. [WebCategoryAttribute ("Appearance")]
  207. public virtual string SelectImageUrl {
  208. get {
  209. object ob = ViewState ["SelectImageUrl"];
  210. if (ob != null) return (string) ob;
  211. return "";
  212. }
  213. set {
  214. ViewState ["SelectImageUrl"] = value;
  215. OnFieldChanged ();
  216. }
  217. }
  218. [LocalizableAttribute (true)]
  219. [WebSysDescription ("")]
  220. [WebCategoryAttribute ("Appearance")]
  221. public virtual string SelectText {
  222. get {
  223. object ob = ViewState ["SelectText"];
  224. if (ob != null) return (string) ob;
  225. return "Select";
  226. }
  227. set {
  228. ViewState ["SelectText"] = value;
  229. OnFieldChanged ();
  230. }
  231. }
  232. [DefaultValueAttribute (true)]
  233. [WebSysDescription ("")]
  234. [WebCategoryAttribute ("Behavior")]
  235. public virtual bool ShowCancelButton {
  236. get {
  237. object ob = ViewState ["ShowCancelButton"];
  238. if (ob != null) return (bool) ob;
  239. return true;
  240. }
  241. set {
  242. ViewState ["ShowCancelButton"] = value;
  243. OnFieldChanged ();
  244. }
  245. }
  246. [DefaultValueAttribute (false)]
  247. [WebSysDescription ("")]
  248. [WebCategoryAttribute ("Behavior")]
  249. public virtual bool ShowDeleteButton {
  250. get {
  251. object ob = ViewState ["ShowDeleteButton"];
  252. if (ob != null) return (bool) ob;
  253. return false;
  254. }
  255. set {
  256. ViewState ["ShowDeleteButton"] = value;
  257. OnFieldChanged ();
  258. }
  259. }
  260. [DefaultValueAttribute (false)]
  261. [WebSysDescription ("")]
  262. [WebCategoryAttribute ("Behavior")]
  263. public virtual bool ShowEditButton {
  264. get {
  265. object ob = ViewState ["ShowEditButton"];
  266. if (ob != null) return (bool) ob;
  267. return false;
  268. }
  269. set {
  270. ViewState ["ShowEditButton"] = value;
  271. OnFieldChanged ();
  272. }
  273. }
  274. [DefaultValueAttribute (false)]
  275. [WebSysDescription ("")]
  276. [WebCategoryAttribute ("Behavior")]
  277. public virtual bool ShowSelectButton {
  278. get {
  279. object ob = ViewState ["ShowSelectButton"];
  280. if (ob != null) return (bool) ob;
  281. return false;
  282. }
  283. set {
  284. ViewState ["ShowSelectButton"] = value;
  285. OnFieldChanged ();
  286. }
  287. }
  288. [DefaultValueAttribute (false)]
  289. [WebSysDescription ("")]
  290. [WebCategoryAttribute ("Behavior")]
  291. public virtual bool ShowInsertButton {
  292. get {
  293. object ob = ViewState ["ShowInsertButton"];
  294. if (ob != null) return (bool) ob;
  295. return false;
  296. }
  297. set {
  298. ViewState ["ShowInsertButton"] = value;
  299. OnFieldChanged ();
  300. }
  301. }
  302. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  303. [UrlPropertyAttribute]
  304. [DefaultValueAttribute ("")]
  305. [WebSysDescription ("")]
  306. [WebCategoryAttribute ("Appearance")]
  307. public virtual string UpdateImageUrl {
  308. get {
  309. object ob = ViewState ["UpdateImageUrl"];
  310. if (ob != null) return (string) ob;
  311. return "";
  312. }
  313. set {
  314. ViewState ["UpdateImageUrl"] = value;
  315. OnFieldChanged ();
  316. }
  317. }
  318. [LocalizableAttribute (true)]
  319. [WebSysDescription ("")]
  320. [WebCategoryAttribute ("Appearance")]
  321. public virtual string UpdateText {
  322. get {
  323. object ob = ViewState ["UpdateText"];
  324. if (ob != null) return (string) ob;
  325. return "Update";
  326. }
  327. set {
  328. ViewState ["UpdateText"] = value;
  329. OnFieldChanged ();
  330. }
  331. }
  332. public override void InitializeCell (DataControlFieldCell cell,
  333. DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
  334. {
  335. string index = rowIndex.ToString ();
  336. if (cellType == DataControlCellType.DataCell)
  337. {
  338. if ((rowState & DataControlRowState.Edit) != 0) {
  339. cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
  340. if (ShowCancelButton) {
  341. AddSeparator (cell);
  342. cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
  343. }
  344. } else if ((rowState & DataControlRowState.Insert) != 0) {
  345. cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
  346. if (ShowCancelButton) {
  347. AddSeparator (cell);
  348. cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
  349. }
  350. } else {
  351. if (ShowEditButton) {
  352. AddSeparator (cell);
  353. cell.Controls.Add (CreateButton (EditText, EditImageUrl, DataControlCommands.EditCommandName, index));
  354. }
  355. if (ShowDeleteButton) {
  356. AddSeparator (cell);
  357. cell.Controls.Add (CreateButton (DeleteText, DeleteImageUrl, DataControlCommands.DeleteCommandName, index));
  358. }
  359. if (ShowSelectButton) {
  360. AddSeparator (cell);
  361. cell.Controls.Add (CreateButton (SelectText, SelectImageUrl, DataControlCommands.SelectCommandName, index));
  362. }
  363. if (ShowInsertButton) {
  364. AddSeparator (cell);
  365. cell.Controls.Add (CreateButton (NewText, NewImageUrl, DataControlCommands.NewCommandName, index));
  366. }
  367. }
  368. } else
  369. base.InitializeCell (cell, cellType, rowState, rowIndex);
  370. }
  371. DataControlButton CreateButton (string text, string image, string command, string arg)
  372. {
  373. DataControlButton c = new DataControlButton (Control, text, image, command, arg, false);
  374. c.CausesValidation = CausesValidation;
  375. return c;
  376. }
  377. void AddSeparator (DataControlFieldCell cell)
  378. {
  379. if (cell.Controls.Count > 0) {
  380. Literal lit = new Literal ();
  381. lit.Text = " ";
  382. cell.Controls.Add (lit);
  383. }
  384. }
  385. protected override DataControlField CreateField ()
  386. {
  387. return new CommandField ();
  388. }
  389. protected override void CopyProperties (DataControlField newField)
  390. {
  391. base.CopyProperties (newField);
  392. CommandField field = (CommandField) newField;
  393. field.CancelImageUrl = CancelImageUrl;
  394. field.CancelText = CancelText;
  395. field.DeleteImageUrl = DeleteImageUrl;
  396. field.DeleteText = DeleteText;
  397. field.EditImageUrl = EditImageUrl;
  398. field.EditText = EditText;
  399. field.InsertImageUrl = InsertImageUrl;
  400. field.InsertText = InsertText;
  401. field.NewImageUrl = NewImageUrl;
  402. field.NewText = NewText;
  403. field.SelectImageUrl = SelectImageUrl;
  404. field.SelectText = SelectText;
  405. field.ShowCancelButton = ShowCancelButton;
  406. field.ShowDeleteButton = ShowDeleteButton;
  407. field.ShowEditButton = ShowEditButton;
  408. field.ShowSelectButton = ShowSelectButton;
  409. field.ShowInsertButton = ShowInsertButton;
  410. field.UpdateImageUrl = UpdateImageUrl;
  411. field.UpdateText = UpdateText;
  412. }
  413. public override void ValidateSupportsCallback ()
  414. {
  415. }
  416. }
  417. }
  418. #endif