// CAS
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public class BoundColumn : DataGridColumn {
-
- private string data_format_string;
+ public class BoundColumn : DataGridColumn
+ {
+ string data_format_string;
public BoundColumn ()
{
{
base.InitializeCell (cell, columnIndex, itemType);
+ string df = DataField;
+
switch (itemType) {
case ListItemType.Item:
- case ListItemType.EditItem:
+ case ListItemType.SelectedItem:
case ListItemType.AlternatingItem:
- cell.DataBinding += new EventHandler (ItemDataBinding);
+ if (df != null && df.Length != 0)
+ cell.DataBinding += new EventHandler (ItemDataBinding);
+ break;
+ case ListItemType.EditItem:
+ if (ReadOnly && df != null && df.Length != 0) {
+ cell.DataBinding += new EventHandler (ItemDataBinding);
+ break;
+ }
+ TextBox tb = new TextBox ();
+ if (df != null && df.Length != 0)
+ tb.DataBinding += new EventHandler (ItemDataBinding);
+ cell.Controls.Add (tb);
break;
}
}
return String.Format (data_format_string, dataValue);
}
- private void ItemDataBinding (object sender, EventArgs e)
+ string GetValueFromItem (DataGridItem item)
{
- TableCell cell = (TableCell) sender;
- DataGridItem item = (DataGridItem) cell.NamingContainer;
- object value = null;
-
+ object val;
if (DataField != thisExpr) {
- value = DataBinder.Eval (item.DataItem, DataField);
+ val = DataBinder.Eval (item.DataItem, DataField);
} else {
- value = item.DataItem;
+ val = item.DataItem;
}
- string text = FormatDataValue (value);
- if (text == String.Empty)
- text = " ";
- cell.Text = text;
+ string text = FormatDataValue (val);
+ return (text != "" ? text : " ");
+ }
+
+ void ItemDataBinding (object sender, EventArgs e)
+ {
+ Control ctrl = (Control) sender;
+ string text = GetValueFromItem ((DataGridItem) ctrl.NamingContainer);
+
+ TableCell cell = sender as TableCell;
+ if (cell == null) {
+ TextBox tb = (TextBox) sender;
+ tb.Text = text;
+ } else {
+ cell.Text = text;
+ }
}
}
}
+