5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Marek Habersack <mhabersack@novell.com>
8 // Copyright (C) 2008-2009 Novell Inc. http://novell.com
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
33 using System
.Collections
.Generic
;
34 using System
.Collections
.Specialized
;
35 using System
.Globalization
;
36 using System
.Security
.Permissions
;
37 using System
.Security
.Principal
;
38 using System
.Web
.Caching
;
40 using System
.Web
.UI
.WebControls
;
42 namespace System
.Web
.DynamicData
44 [AspNetHostingPermission (SecurityAction
.InheritanceDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
45 [AspNetHostingPermission (SecurityAction
.LinkDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
46 public class DynamicField
: DataControlField
, IAttributeAccessor
, IFieldFormattingOptions
49 Dictionary
<string, string> attributes
;
51 public DynamicField ()
53 DataFormatString
= String
.Empty
;
55 NullDisplayText
= String
.Empty
;
58 public bool ApplyFormatInEditMode
{
62 public bool ConvertEmptyStringToNull
{
66 public virtual string DataField
{
67 get { return ViewState.GetString ("_DataField", String.Empty); }
69 ViewState
["_DataField"] = value;
74 public string DataFormatString
{
78 public override string HeaderText
{
80 string s
= ViewState
.GetString ("headerText", null);
84 MetaColumn column
= MyColumn
;
86 return column
.DisplayName
;
91 set { base.HeaderText = value; }
94 public bool HtmlEncode
{
100 if (myColumn
!= null)
102 Control owner
= Control
;
106 MetaTable table
= owner
.FindMetaTable ();
110 myColumn
= table
.GetColumn (DataField
);
115 public string NullDisplayText
{
119 public override string SortExpression
{
121 string s
= ViewState
.GetString ("sortExpression", null);
125 MetaColumn column
= MyColumn
;
127 return column
.SortExpression
;
132 set { base.SortExpression = value; }
135 public virtual string UIHint
{
137 string s
= ViewState
.GetString ("uiHint", null);
144 ViewState
["uiHint"] = value;
150 protected override void CopyProperties (DataControlField newField
)
152 throw new NotImplementedException ();
156 protected override DataControlField
CreateField ()
158 throw new NotImplementedException ();
162 public override void ExtractValuesFromCell (IOrderedDictionary dictionary
, DataControlFieldCell cell
, DataControlRowState rowState
, bool includeReadOnly
)
164 throw new NotImplementedException ();
167 public string GetAttribute (string key
)
169 if (attributes
== null)
173 if (attributes
.TryGetValue (key
, out ret
))
179 public override void InitializeCell (DataControlFieldCell cell
, DataControlCellType cellType
, DataControlRowState rowState
, int rowIndex
)
181 if (cellType
== DataControlCellType
.Header
|| cellType
== DataControlCellType
.Footer
) {
182 base.InitializeCell (cell
, cellType
, rowState
, rowIndex
);
186 DynamicControl dc
= new DynamicControl ();
187 dc
.ApplyFormatInEditMode
= ApplyFormatInEditMode
;
188 dc
.ConvertEmptyStringToNull
= ConvertEmptyStringToNull
;
189 dc
.Column
= MyColumn
;
190 dc
.DataField
= DataField
;
191 dc
.DataFormatString
= DataFormatString
;
192 dc
.HtmlEncode
= HtmlEncode
;
193 dc
.Mode
= (rowState
& DataControlRowState
.Edit
) != 0 ? DataBoundControlMode
.Edit
:
194 (rowState
& DataControlRowState
.Insert
) != 0 ? DataBoundControlMode
.Insert
: DataBoundControlMode
.ReadOnly
;
195 dc
.NullDisplayText
= NullDisplayText
;
197 dc
.InternalSetAttributes (attributes
);
199 cell
.Controls
.Add (dc
);
202 public void SetAttribute (string key
, string value)
204 if (attributes
== null)
205 attributes
= new Dictionary
<string, string> ();
207 if (attributes
.ContainsKey (key
))
208 attributes
[key
] = value;
210 attributes
.Add (key
, value);