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 {
50 get { return ViewState.GetString ("CancelImageUrl", ""); }
52 ViewState ["CancelImageUrl"] = value;
57 [LocalizableAttribute (true)]
58 [WebSysDescription ("")]
59 [WebCategoryAttribute ("Appearance")]
60 public virtual string CancelText {
61 get { return ViewState.GetString ("CancelText", "Cancel"); }
63 ViewState ["CancelText"] = value;
68 [DefaultValueAttribute (true)]
69 public override bool CausesValidation {
70 get { return ViewState.GetBool ("CausesValidation", true); }
72 ViewState ["CausesValidation"] = value;
77 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
78 [UrlPropertyAttribute]
79 [DefaultValueAttribute ("")]
80 [WebSysDescription ("")]
81 [WebCategoryAttribute ("Appearance")]
82 public virtual string DeleteImageUrl {
83 get { return ViewState.GetString ("DeleteImageUrl", ""); }
85 ViewState ["DeleteImageUrl"] = value;
90 [LocalizableAttribute (true)]
91 [WebSysDescription ("")]
92 [WebCategoryAttribute ("Appearance")]
93 public virtual string DeleteText {
94 get { return ViewState.GetString ("DeleteText", "Delete"); }
96 ViewState ["DeleteText"] = value;
101 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
102 [UrlPropertyAttribute]
103 [DefaultValueAttribute ("")]
104 [WebSysDescription ("")]
105 [WebCategoryAttribute ("Appearance")]
106 public virtual string EditImageUrl {
107 get { return ViewState.GetString ("EditImageUrl", ""); }
109 ViewState ["EditImageUrl"] = value;
114 [LocalizableAttribute (true)]
115 [WebSysDescription ("")]
116 [WebCategoryAttribute ("Appearance")]
117 public virtual string EditText {
118 get { return ViewState.GetString ("EditText", "Edit"); }
120 ViewState ["EditText"] = value;
125 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
126 [UrlPropertyAttribute]
127 [DefaultValueAttribute ("")]
128 [WebSysDescription ("")]
129 [WebCategoryAttribute ("Appearance")]
130 public virtual string InsertImageUrl {
131 get { return ViewState.GetString ("InsertImageUrl", ""); }
133 ViewState ["InsertImageUrl"] = value;
138 [LocalizableAttribute (true)]
139 [WebSysDescription ("")]
140 [WebCategoryAttribute ("Appearance")]
141 public virtual string InsertText {
142 get { return ViewState.GetString ("InsertText", "Insert"); }
144 ViewState ["InsertText"] = value;
149 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
150 [UrlPropertyAttribute]
151 [DefaultValueAttribute ("")]
152 [WebSysDescription ("")]
153 [WebCategoryAttribute ("Appearance")]
154 public virtual string NewImageUrl {
155 get { return ViewState.GetString ("NewImageUrl", ""); }
157 ViewState ["NewImageUrl"] = value;
162 [LocalizableAttribute (true)]
163 [WebSysDescription ("")]
164 [WebCategoryAttribute ("Appearance")]
165 public virtual string NewText {
166 get { return ViewState.GetString ("NewText", "New"); }
168 ViewState ["NewText"] = value;
173 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
174 [UrlPropertyAttribute]
175 [DefaultValueAttribute ("")]
176 [WebSysDescription ("")]
177 [WebCategoryAttribute ("Appearance")]
178 public virtual string SelectImageUrl {
179 get { return ViewState.GetString ("SelectImageUrl", ""); }
181 ViewState ["SelectImageUrl"] = value;
186 [LocalizableAttribute (true)]
187 [WebSysDescription ("")]
188 [WebCategoryAttribute ("Appearance")]
189 public virtual string SelectText {
190 get { return ViewState.GetString ("SelectText", "Select"); }
192 ViewState ["SelectText"] = value;
197 [DefaultValueAttribute (true)]
198 [WebSysDescription ("")]
199 [WebCategoryAttribute ("Behavior")]
200 public virtual bool ShowCancelButton {
201 get { return ViewState.GetBool ("ShowCancelButton", true); }
203 ViewState ["ShowCancelButton"] = value;
208 [DefaultValueAttribute (false)]
209 [WebSysDescription ("")]
210 [WebCategoryAttribute ("Behavior")]
211 public virtual bool ShowDeleteButton {
212 get { return ViewState.GetBool ("ShowDeleteButton", false); }
214 ViewState ["ShowDeleteButton"] = value;
219 [DefaultValueAttribute (false)]
220 [WebSysDescription ("")]
221 [WebCategoryAttribute ("Behavior")]
222 public virtual bool ShowEditButton {
223 get { return ViewState.GetBool ("ShowEditButton", false); }
225 ViewState ["ShowEditButton"] = value;
230 [DefaultValueAttribute (false)]
231 [WebSysDescription ("")]
232 [WebCategoryAttribute ("Behavior")]
233 public virtual bool ShowSelectButton {
234 get { return ViewState.GetBool ("ShowSelectButton", false); }
236 ViewState ["ShowSelectButton"] = value;
241 [DefaultValueAttribute (false)]
242 [WebSysDescription ("")]
243 [WebCategoryAttribute ("Behavior")]
244 public virtual bool ShowInsertButton {
245 get { return ViewState.GetBool ("ShowInsertButton", false); }
247 ViewState ["ShowInsertButton"] = value;
252 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
253 [UrlPropertyAttribute]
254 [DefaultValueAttribute ("")]
255 [WebSysDescription ("")]
256 [WebCategoryAttribute ("Appearance")]
257 public virtual string UpdateImageUrl {
258 get { return ViewState.GetString ("UpdateImageUrl", ""); }
260 ViewState ["UpdateImageUrl"] = value;
265 [LocalizableAttribute (true)]
266 [WebSysDescription ("")]
267 [WebCategoryAttribute ("Appearance")]
268 public virtual string UpdateText {
269 get { return ViewState.GetString ("UpdateText", "Update"); }
271 ViewState ["UpdateText"] = value;
276 public override void InitializeCell (DataControlFieldCell cell,
277 DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
279 string index = rowIndex.ToString ();
281 if (cellType == DataControlCellType.DataCell)
283 if ((rowState & DataControlRowState.Edit) != 0) {
284 cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
285 if (ShowCancelButton) {
287 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
289 } else if ((rowState & DataControlRowState.Insert) != 0) {
290 cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
291 if (ShowCancelButton) {
293 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
296 if (ShowEditButton) {
298 cell.Controls.Add (CreateButton (EditText, EditImageUrl, DataControlCommands.EditCommandName, index));
300 if (ShowDeleteButton) {
302 cell.Controls.Add (CreateButton (DeleteText, DeleteImageUrl, DataControlCommands.DeleteCommandName, index));
304 if (ShowInsertButton) {
306 cell.Controls.Add (CreateButton (NewText, NewImageUrl, DataControlCommands.NewCommandName, index));
308 if (ShowSelectButton) {
310 cell.Controls.Add (CreateButton (SelectText, SelectImageUrl, DataControlCommands.SelectCommandName, index));
314 base.InitializeCell (cell, cellType, rowState, rowIndex);
317 DataControlButton CreateButton (string text, string image, string command, string arg)
319 DataControlButton c = new DataControlButton (Control, text, image, command, arg, false);
320 c.CausesValidation = CausesValidation;
324 void AddSeparator (DataControlFieldCell cell)
326 if (cell.Controls.Count > 0) {
327 Literal lit = new Literal ();
329 cell.Controls.Add (lit);
333 protected override DataControlField CreateField ()
335 return new CommandField ();
338 protected override void CopyProperties (DataControlField newField)
340 base.CopyProperties (newField);
341 CommandField field = (CommandField) newField;
342 field.CancelImageUrl = CancelImageUrl;
343 field.CancelText = CancelText;
344 field.DeleteImageUrl = DeleteImageUrl;
345 field.DeleteText = DeleteText;
346 field.EditImageUrl = EditImageUrl;
347 field.EditText = EditText;
348 field.InsertImageUrl = InsertImageUrl;
349 field.InsertText = InsertText;
350 field.NewImageUrl = NewImageUrl;
351 field.NewText = NewText;
352 field.SelectImageUrl = SelectImageUrl;
353 field.SelectText = SelectText;
354 field.ShowCancelButton = ShowCancelButton;
355 field.ShowDeleteButton = ShowDeleteButton;
356 field.ShowEditButton = ShowEditButton;
357 field.ShowSelectButton = ShowSelectButton;
358 field.ShowInsertButton = ShowInsertButton;
359 field.UpdateImageUrl = UpdateImageUrl;
360 field.UpdateText = UpdateText;
363 public override void ValidateSupportsCallback ()
365 if (ShowSelectButton)
\r
366 throw new NotSupportedException ("ShowSelectButton = true");