2 // System.Web.UI.WebControls.CommandField.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.Security.Permissions;
38 namespace System.Web.UI.WebControls {
40 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 public class CommandField : ButtonFieldBase
44 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
45 [UrlPropertyAttribute]
46 [DefaultValueAttribute ("")]
47 [WebSysDescription ("")]
48 [WebCategoryAttribute ("Appearance")]
49 public virtual string CancelImageUrl {
51 object ob = ViewState ["CancelImageUrl"];
52 if (ob != null) return (string) ob;
56 ViewState ["CancelImageUrl"] = value;
61 [LocalizableAttribute (true)]
62 [WebSysDescription ("")]
63 [WebCategoryAttribute ("Appearance")]
64 public virtual string CancelText {
66 object ob = ViewState ["CancelText"];
67 if (ob != null) return (string) ob;
71 ViewState ["CancelText"] = value;
76 [DefaultValueAttribute (true)]
\r
77 public override bool CausesValidation {
79 object ob = ViewState ["CausesValidation"];
80 if (ob != null) return (bool) ob;
84 ViewState ["CausesValidation"] = value;
89 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
90 [UrlPropertyAttribute]
91 [DefaultValueAttribute ("")]
92 [WebSysDescription ("")]
93 [WebCategoryAttribute ("Appearance")]
94 public virtual string DeleteImageUrl {
96 object ob = ViewState ["DeleteImageUrl"];
97 if (ob != null) return (string) ob;
101 ViewState ["DeleteImageUrl"] = value;
106 [LocalizableAttribute (true)]
107 [WebSysDescription ("")]
108 [WebCategoryAttribute ("Appearance")]
109 public virtual string DeleteText {
111 object ob = ViewState ["DeleteText"];
112 if (ob != null) return (string) ob;
116 ViewState ["DeleteText"] = value;
121 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
122 [UrlPropertyAttribute]
123 [DefaultValueAttribute ("")]
124 [WebSysDescription ("")]
125 [WebCategoryAttribute ("Appearance")]
126 public virtual string EditImageUrl {
128 object ob = ViewState ["EditImageUrl"];
129 if (ob != null) return (string) ob;
133 ViewState ["EditImageUrl"] = value;
138 [LocalizableAttribute (true)]
139 [WebSysDescription ("")]
140 [WebCategoryAttribute ("Appearance")]
141 public virtual string EditText {
143 object ob = ViewState ["EditText"];
144 if (ob != null) return (string) ob;
148 ViewState ["EditText"] = value;
153 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
154 [UrlPropertyAttribute]
155 [DefaultValueAttribute ("")]
156 [WebSysDescription ("")]
157 [WebCategoryAttribute ("Appearance")]
158 public virtual string InsertImageUrl {
160 object ob = ViewState ["InsertImageUrl"];
161 if (ob != null) return (string) ob;
165 ViewState ["InsertImageUrl"] = value;
170 [LocalizableAttribute (true)]
171 [WebSysDescription ("")]
172 [WebCategoryAttribute ("Appearance")]
173 public virtual string InsertText {
175 object ob = ViewState ["InsertText"];
176 if (ob != null) return (string) ob;
180 ViewState ["InsertText"] = value;
185 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
186 [UrlPropertyAttribute]
187 [DefaultValueAttribute ("")]
188 [WebSysDescription ("")]
189 [WebCategoryAttribute ("Appearance")]
190 public virtual string NewImageUrl {
192 object ob = ViewState ["NewImageUrl"];
193 if (ob != null) return (string) ob;
197 ViewState ["NewImageUrl"] = value;
202 [LocalizableAttribute (true)]
203 [WebSysDescription ("")]
204 [WebCategoryAttribute ("Appearance")]
205 public virtual string NewText {
207 object ob = ViewState ["NewText"];
208 if (ob != null) return (string) ob;
212 ViewState ["NewText"] = value;
217 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
218 [UrlPropertyAttribute]
219 [DefaultValueAttribute ("")]
220 [WebSysDescription ("")]
221 [WebCategoryAttribute ("Appearance")]
222 public virtual string SelectImageUrl {
224 object ob = ViewState ["SelectImageUrl"];
225 if (ob != null) return (string) ob;
229 ViewState ["SelectImageUrl"] = value;
234 [LocalizableAttribute (true)]
235 [WebSysDescription ("")]
236 [WebCategoryAttribute ("Appearance")]
237 public virtual string SelectText {
239 object ob = ViewState ["SelectText"];
240 if (ob != null) return (string) ob;
244 ViewState ["SelectText"] = value;
249 [DefaultValueAttribute (true)]
250 [WebSysDescription ("")]
251 [WebCategoryAttribute ("Behavior")]
252 public virtual bool ShowCancelButton {
254 object ob = ViewState ["ShowCancelButton"];
255 if (ob != null) return (bool) ob;
259 ViewState ["ShowCancelButton"] = value;
264 [DefaultValueAttribute (false)]
265 [WebSysDescription ("")]
266 [WebCategoryAttribute ("Behavior")]
267 public virtual bool ShowDeleteButton {
269 object ob = ViewState ["ShowDeleteButton"];
270 if (ob != null) return (bool) ob;
274 ViewState ["ShowDeleteButton"] = value;
279 [DefaultValueAttribute (false)]
280 [WebSysDescription ("")]
281 [WebCategoryAttribute ("Behavior")]
282 public virtual bool ShowEditButton {
284 object ob = ViewState ["ShowEditButton"];
285 if (ob != null) return (bool) ob;
289 ViewState ["ShowEditButton"] = value;
294 [DefaultValueAttribute (false)]
295 [WebSysDescription ("")]
296 [WebCategoryAttribute ("Behavior")]
297 public virtual bool ShowSelectButton {
299 object ob = ViewState ["ShowSelectButton"];
300 if (ob != null) return (bool) ob;
304 ViewState ["ShowSelectButton"] = value;
309 [DefaultValueAttribute (false)]
310 [WebSysDescription ("")]
311 [WebCategoryAttribute ("Behavior")]
312 public virtual bool ShowInsertButton {
314 object ob = ViewState ["ShowInsertButton"];
315 if (ob != null) return (bool) ob;
319 ViewState ["ShowInsertButton"] = value;
324 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
325 [UrlPropertyAttribute]
326 [DefaultValueAttribute ("")]
327 [WebSysDescription ("")]
328 [WebCategoryAttribute ("Appearance")]
329 public virtual string UpdateImageUrl {
331 object ob = ViewState ["UpdateImageUrl"];
332 if (ob != null) return (string) ob;
336 ViewState ["UpdateImageUrl"] = value;
341 [LocalizableAttribute (true)]
342 [WebSysDescription ("")]
343 [WebCategoryAttribute ("Appearance")]
344 public virtual string UpdateText {
346 object ob = ViewState ["UpdateText"];
347 if (ob != null) return (string) ob;
351 ViewState ["UpdateText"] = value;
356 public override void InitializeCell (DataControlFieldCell cell,
357 DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
359 string index = rowIndex.ToString ();
361 if (cellType == DataControlCellType.DataCell)
363 if ((rowState & DataControlRowState.Edit) != 0) {
364 cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
365 if (ShowCancelButton) {
367 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
369 } else if ((rowState & DataControlRowState.Insert) != 0) {
370 cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
371 if (ShowCancelButton) {
373 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
376 if (ShowEditButton) {
378 cell.Controls.Add (CreateButton (EditText, EditImageUrl, DataControlCommands.EditCommandName, index));
380 if (ShowDeleteButton) {
382 cell.Controls.Add (CreateButton (DeleteText, DeleteImageUrl, DataControlCommands.DeleteCommandName, index));
384 if (ShowSelectButton) {
386 cell.Controls.Add (CreateButton (SelectText, SelectImageUrl, DataControlCommands.SelectCommandName, index));
388 if (ShowInsertButton) {
390 cell.Controls.Add (CreateButton (NewText, NewImageUrl, DataControlCommands.NewCommandName, index));
394 base.InitializeCell (cell, cellType, rowState, rowIndex);
397 DataControlButton CreateButton (string text, string image, string command, string arg)
399 DataControlButton c = new DataControlButton (Control, text, image, command, arg, false);
400 c.CausesValidation = CausesValidation;
404 void AddSeparator (DataControlFieldCell cell)
406 if (cell.Controls.Count > 0) {
407 Literal lit = new Literal ();
409 cell.Controls.Add (lit);
413 protected override DataControlField CreateField ()
415 return new CommandField ();
418 protected override void CopyProperties (DataControlField newField)
420 base.CopyProperties (newField);
421 CommandField field = (CommandField) newField;
422 field.CancelImageUrl = CancelImageUrl;
423 field.CancelText = CancelText;
424 field.DeleteImageUrl = DeleteImageUrl;
425 field.DeleteText = DeleteText;
426 field.EditImageUrl = EditImageUrl;
427 field.EditText = EditText;
428 field.InsertImageUrl = InsertImageUrl;
429 field.InsertText = InsertText;
430 field.NewImageUrl = NewImageUrl;
431 field.NewText = NewText;
432 field.SelectImageUrl = SelectImageUrl;
433 field.SelectText = SelectText;
434 field.ShowCancelButton = ShowCancelButton;
435 field.ShowDeleteButton = ShowDeleteButton;
436 field.ShowEditButton = ShowEditButton;
437 field.ShowSelectButton = ShowSelectButton;
438 field.ShowInsertButton = ShowInsertButton;
439 field.UpdateImageUrl = UpdateImageUrl;
440 field.UpdateText = UpdateText;
443 public override void ValidateSupportsCallback ()