//
using System.ComponentModel;
+using System.Security.Permissions;
namespace System.Web.UI.WebControls {
- public class BoundColumn : DataGridColumn
- {
- private string data_format_string;
+ // CAS
+ [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+ public class BoundColumn : DataGridColumn
+ {
+ string data_format_string;
public BoundColumn ()
{
public static readonly string thisExpr = "!";
[DefaultValue("")]
+ [WebSysDescription ("")]
+ [WebCategory ("Misc")]
public virtual string DataField
{
get {
}
[DefaultValue("")]
+ [WebSysDescription ("")]
+ [WebCategory ("Misc")]
public virtual string DataFormatString
{
get {
}
[DefaultValue(false)]
+ [WebSysDescription ("")]
+ [WebCategory ("Misc")]
public virtual bool ReadOnly
{
get {
{
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;
}
}
protected virtual string FormatDataValue (object dataValue)
{
+ if (dataValue == null)
+ return "";
+
if (data_format_string == String.Empty)
return dataValue.ToString ();
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;
- string text = null;
-
+ object val;
if (DataField != thisExpr) {
- try {
- value = DataBinder.Eval (item.DataItem, DataField);
- } catch {
- value = String.Empty;
- }
+ val = DataBinder.Eval (item.DataItem, DataField);
} else {
- value = item.DataItem;
+ val = item.DataItem;
}
- 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;
+ }
}
}
}
+