PropertyDescriptor boundProperty;
- [MonoTODO]
[DefaultValueAttribute (false)]
[WebSysDescription ("")]
[WebCategoryAttribute ("Behavior")]
public virtual bool ApplyFormatInEditMode {
get {
- throw new NotImplementedException ();
+ return ViewState.GetBool ("ApplyFormatInEditMode", false);
}
set {
- throw new NotImplementedException ();
+ ViewState ["ApplyFormatInEditMode"] = value;
}
}
[WebSysDescription ("")]
[WebCategoryAttribute ("Behavior")]
public virtual bool ConvertEmptyStringToNull {
- get { return ViewState.GetBool ("ConvertEmptyStringToNull", false); }
+ get { return ViewState.GetBool ("ConvertEmptyStringToNull", true); }
set {
ViewState ["ConvertEmptyStringToNull"] = value;
OnFieldChanged ();
[DefaultValueAttribute ("")]
[WebCategoryAttribute ("Behavior")]
public virtual string NullDisplayText {
- get { return ViewState.GetString ("NullDisplaytext", ""); }
+ get { return ViewState.GetString ("NullDisplayText", ""); }
set {
ViewState ["NullDisplayText"] = value;
OnFieldChanged ();
[WebSysDescription ("")]
[WebCategoryAttribute ("HtmlEncode")]
public virtual bool HtmlEncode {
- get { return ViewState.GetBool ("ReadOnly", true); }
+ get { return ViewState.GetBool ("HtmlEncode", true); }
set {
- ViewState ["HtmlEncode"] = true;
+ ViewState ["HtmlEncode"] = value;
OnFieldChanged ();
}
}
protected virtual string FormatDataValue (object value, bool encode)
{
string res;
- if (value == null || (value.ToString().Length == 0 && ConvertEmptyStringToNull))
- res = NullDisplayText;
+ if (value == null || (value.ToString ().Length == 0 && ConvertEmptyStringToNull)) {
+ if (NullDisplayText.Length == 0) {
+ encode = false;
+ res = " ";
+ }
+ else
+ res = NullDisplayText;
+ }
else if (DataFormatString.Length > 0)
res = string.Format (DataFormatString, value);
else
{
return GetBoundValue (Control);
}
-
+
object GetBoundValue (Control controlContainer)
{
+ object dataItem = DataBinder.GetDataItem (controlContainer);
+ if (dataItem == null)
+ throw new HttpException ("A data item was not found in the container. The container must either implement IDataItemContainer, or have a property named DataItem.");
+
if (DataField == ThisExpression)
- return controlContainer.ToString ();
- else {
- IDataItemContainer dic = (IDataItemContainer) controlContainer;
- if (boundProperty == null) {
- boundProperty = TypeDescriptor.GetProperties (dic.DataItem) [DataField];
- if (boundProperty == null)
- throw new InvalidOperationException ("Property '" + DataField + "' not found in object of type " + dic.DataItem.GetType());
- }
- return boundProperty.GetValue (dic.DataItem);
- }
+ return dataItem.ToString ();
+ else if (DataField == string.Empty)
+ return null;
+
+ return DataBinder.GetPropertyValue (dataItem, DataField);
}
protected virtual void OnDataBindField (object sender, EventArgs e)
{
- DataControlFieldCell cell = (DataControlFieldCell) sender;
+ Control cell = (Control) sender;
+ Control controlContainer = cell.BindingContainer;
+ if (!(controlContainer is INamingContainer))
+ throw new HttpException ("A DataControlField must be within an INamingContainer.");
+ object val = GetValue (controlContainer);
+
if (cell.Controls.Count > 0) {
TextBox box = (TextBox) cell.Controls [0];
- object val = GetValue (cell.BindingContainer);
- box.Text = val != null ? val.ToString() : "";
+ if (ApplyFormatInEditMode)
+ box.Text = FormatDataValue (val, SupportsHtmlEncode && HtmlEncode);
+ else
+ box.Text = val != null ? val.ToString() : NullDisplayText;
}
else
- cell.Text = FormatDataValue (GetValue (cell.BindingContainer), SupportsHtmlEncode && HtmlEncode);
+ ((DataControlFieldCell)cell).Text = FormatDataValue (val, SupportsHtmlEncode && HtmlEncode);
}
protected override DataControlField CreateField ()