1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2005-2010 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Peter Bartok (pbartok@novell.com)
//
//
using System.ComponentModel;
using System.Security.Permissions;
namespace System.Web.UI.WebControls
{
// CAS
[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class EditCommandColumn : DataGridColumn
{
#region Public Constructors
public EditCommandColumn()
{
}
#endregion // Public Constructors
#region Public Instance Properties
[DefaultValue (ButtonColumnType.LinkButton)]
public virtual ButtonColumnType ButtonType {
get {
object obj;
obj = ViewState["ButtonType"];
if (obj != null)
return (ButtonColumnType)obj;
return ButtonColumnType.LinkButton;
}
set { ViewState["ButtonType"] = value; }
}
[DefaultValue ("")]
[Localizable (true)]
public virtual string CancelText {
get { return ViewState.GetString("CancelText", String.Empty); }
set { ViewState["CancelText"] = value; }
}
[DefaultValue(true)]
public virtual bool CausesValidation {
get { return ViewState.GetBool ("CausesValidation", true); }
set { ViewState ["CausesValidation"] = value; }
}
[DefaultValue("")]
public virtual string ValidationGroup {
get { return ViewState.GetString ("ValidationGroup", String.Empty); }
set { ViewState ["ValidationGroup"] = value; }
}
[DefaultValue ("")]
[Localizable (true)]
public virtual string EditText {
get { return ViewState.GetString("EditText", String.Empty); }
set { ViewState["EditText"] = value; }
}
[DefaultValue ("")]
[Localizable (true)]
public virtual string UpdateText {
get { return ViewState.GetString("UpdateText", String.Empty); }
set { ViewState["UpdateText"] = value; }
}
#endregion // Public Instance Properties
#region Public Instance Methods
// Modeled after Ben's CommandField.InitializeCell. Saved me a lot of figuring-out time :-)
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
{
base.InitializeCell (cell, columnIndex, itemType);
switch(itemType) {
case ListItemType.Separator:
case ListItemType.Pager:
case ListItemType.Footer:
case ListItemType.Header: {
// Base handles header and footer, dunno about the others
return;
}
case ListItemType.Item:
case ListItemType.SelectedItem:
case ListItemType.AlternatingItem:{
cell.Controls.Add(CreateButton(ButtonType, EditText, "Edit", false));
break;
}
case ListItemType.EditItem: {
cell.Controls.Add (CreateButton (ButtonType, UpdateText, "Update", CausesValidation));
cell.Controls.Add(new LiteralControl(" "));
cell.Controls.Add(CreateButton(ButtonType, CancelText, "Cancel", false));
break;
}
}
}
#endregion // Public Instance Methods
#region Private Methods
Control CreateButton(ButtonColumnType type, string text, string command, bool valid)
{
Button b;
LinkButton d;
if (type == ButtonColumnType.LinkButton) {
d = new ForeColorLinkButton();
d.Text = text;
d.CommandName = command;
d.CausesValidation = valid;
if (valid)
d.ValidationGroup = ValidationGroup;
return d;
}
b = new Button();
b.Text = text;
b.CommandName = command;
b.CausesValidation = valid;
if (valid)
b.ValidationGroup = ValidationGroup;
return b;
}
#endregion // Private Methods
}
}
|