Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BoundField.cs « System.Web.UI.WebControls « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65dac68329318002b7660bfcfac9936aefa56064 (plain)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//
// System.Web.UI.WebControls.BoundField.cs
//
// Authors:
//	Lluis Sanchez Gual (lluis@novell.com)
//
// (C) 2005 Novell, Inc (http://www.novell.com)
//

//
// 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.
//

#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
using System.Web.UI;
using System.ComponentModel;
using System.Security.Permissions;
using System.Reflection;

namespace System.Web.UI.WebControls {

	[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class BoundField : DataControlField
	{
		public static readonly string ThisExpression = "!";
		
		PropertyDescriptor boundProperty;

		[MonoTODO]
		[DefaultValueAttribute (false)]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Behavior")]
		public virtual bool ApplyFormatInEditMode {
			get {
				throw new NotImplementedException ();
			}
			set {
				throw new NotImplementedException ();
			}
		}
		
		[DefaultValueAttribute (true)]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Behavior")]
		public virtual bool ConvertEmptyStringToNull {
			get { return ViewState.GetBool ("ConvertEmptyStringToNull", false); }
			set {
				ViewState ["ConvertEmptyStringToNull"] = value;
				OnFieldChanged ();
			}
		}

		[TypeConverterAttribute ("System.Web.UI.Design.DataSourceViewSchemaConverter, " + Consts.AssemblySystem_Design)]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Data")]
		[DefaultValueAttribute ("")]
		public virtual string DataField {
			get { return ViewState.GetString ("DataField", ""); }
			set {
				ViewState ["DataField"] = value;
				OnFieldChanged ();
			}
		}

		[DefaultValueAttribute ("")]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Data")]
		public virtual string DataFormatString {
			get { return ViewState.GetString ("DataFormatString", ""); }
			set {
				ViewState ["DataFormatString"] = value;
				OnFieldChanged ();
			}
		}

		[MonoTODO]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Appearance")]
		public override string HeaderText {
			get { return ViewState.GetString ("HeaderText", "");
			}
			set {
				ViewState["HeaderText"] = value;
				OnFieldChanged ();
			}
		}

		[DefaultValueAttribute ("")]
		[WebCategoryAttribute ("Behavior")]
		public virtual string NullDisplayText {
			get { return ViewState.GetString ("NullDisplaytext", ""); }
			set {
				ViewState ["NullDisplayText"] = value;
				OnFieldChanged ();
			}
		}

		[DefaultValueAttribute (false)]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("Behavior")]
		public virtual bool ReadOnly {
			get { return ViewState.GetBool ("ReadOnly", false); }
			set { 
				ViewState ["ReadOnly"] = value;
				OnFieldChanged ();
			}
		}

		[DefaultValueAttribute (true)]
		[WebSysDescription ("")]
		[WebCategoryAttribute ("HtmlEncode")]
		public virtual bool HtmlEncode {
			get { return ViewState.GetBool ("ReadOnly", true); }
			set { 
				ViewState ["HtmlEncode"] = true;
				OnFieldChanged ();
			}
		}

		public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
			DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
		{
			bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
			if (editable && !ReadOnly) {
				if (cell.Controls.Count > 0) {
					TextBox box = (TextBox) cell.Controls [0];
					dictionary [DataField] = box.Text;
				}
			} else if (includeReadOnly) {
				dictionary [DataField] = cell.Text;
			}
		}

		[MonoTODO]
		public override bool Initialize (bool enableSorting, 
						 Control control)
		{
			return base.Initialize (enableSorting, control);
		}

		public override void InitializeCell (DataControlFieldCell cell,
			DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
		{
			base.InitializeCell (cell, cellType, rowState, rowIndex);
			if (cellType == DataControlCellType.DataCell) {
				InitializeDataCell (cell, rowState);
				if ((rowState & DataControlRowState.Insert) == 0)
					cell.DataBinding += new EventHandler (OnDataBindField);
			}
		}
		
		protected virtual void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
		{
			bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
			if (editable && !ReadOnly) {
				TextBox box = new TextBox ();
				cell.Controls.Add (box);
			}
		}
		
		protected virtual bool SupportsHtmlEncode {
			get { return true; }
		}
		
		protected virtual string FormatDataValue (object value, bool encode)
		{
			string res;
			if (value == null || (value.ToString().Length == 0 && ConvertEmptyStringToNull))
				res = NullDisplayText;
			else if (DataFormatString.Length > 0)
				res = string.Format (DataFormatString, value);
			else
				res = value.ToString ();
				
			if (encode) return HttpUtility.HtmlEncode (res);
			else return res;
		}
		
		protected virtual object GetValue (Control controlContainer)
		{
			if (DesignMode)
				return GetDesignTimeValue ();
			else
				return GetBoundValue (controlContainer);
		}
		
		protected virtual object GetDesignTimeValue ()
		{
			return GetBoundValue (Control);
		}
		
		object GetBoundValue (Control controlContainer)
		{
			if (DataField == ThisExpression)
				return controlContainer.ToString ();
			else {
				IDataItemContainer dic = (IDataItemContainer) controlContainer;
				if (boundProperty == null) {
					boundProperty = TypeDescriptor.GetProperties (dic.DataItem) [DataField];
					if (boundProperty == null)
						new InvalidOperationException ("Property '" + DataField + "' not found in object of type " + dic.DataItem.GetType());
				}
				return boundProperty.GetValue (dic.DataItem);
			}
		}
		
		protected virtual void OnDataBindField (object sender, EventArgs e)
		{
			DataControlFieldCell cell = (DataControlFieldCell) sender;
			if (cell.Controls.Count > 0) {
				TextBox box = (TextBox) cell.Controls [0];
				object val = GetValue (cell.BindingContainer);
				box.Text = val != null ? val.ToString() : "";
			}
			else
				cell.Text = FormatDataValue (GetValue (cell.BindingContainer), SupportsHtmlEncode && HtmlEncode);
		}
		
		protected override DataControlField CreateField ()
		{
			return new BoundField ();
		}
		
		protected override void CopyProperties (DataControlField newField)
		{
			base.CopyProperties (newField);
			BoundField field = (BoundField) newField;
			field.ConvertEmptyStringToNull = ConvertEmptyStringToNull;
			field.DataField = DataField;
			field.DataFormatString = DataFormatString;
			field.NullDisplayText = NullDisplayText;
			field.ReadOnly = ReadOnly;
			field.HtmlEncode = HtmlEncode;
		}

		[MonoTODO]
		public override void ValidateSupportsCallback ()
		{
			throw new NotImplementedException ();
		}

	}
}
#endif