X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web.UI.WebControls%2FButtonColumn.cs;h=94d8ee9c046c88e1e78662c358c6f544dfc5041a;hb=c1d81649cc1d16ee47bd6fb951e220d8aba6a1d0;hp=5e79a570825265a756469f4c5f4389885fc1916f;hpb=0abc2e6270020edc4a5b4c66f93b4ae582815f20;p=mono.git diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ButtonColumn.cs b/mcs/class/System.Web/System.Web.UI.WebControls/ButtonColumn.cs old mode 100755 new mode 100644 index 5e79a570825..94d8ee9c046 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ButtonColumn.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ButtonColumn.cs @@ -1,14 +1,11 @@ // // System.Web.UI.WebControls.ButtonColumn.cs // -// Authors: -// Gaurav Vaish (gvaish@iitk.ac.in) -// Andreas Nahr (ClassDevelopment@A-SoftTech.com) +// Author: +// Dick Porter +// Gonzalo Paniagua Javier (gonzalo@ximian.com) // -// (C) Gaurav Vaish (2002) -// (C) 2003 Andreas Nahr -// - +// Copyright (C) 2005-2010 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 @@ -29,192 +26,166 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // - -using System; -using System.ComponentModel; -using System.Web; -using System.Web.UI; - -namespace System.Web.UI.WebControls -{ - public class ButtonColumn : DataGridColumn - { - private PropertyDescriptor textFieldDescriptor; - - public ButtonColumn(): base() - { - } - - public override void Initialize() - { - base.Initialize(); - textFieldDescriptor = null; - } - - public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) - { - base.InitializeCell(cell, columnIndex, itemType); - if (Enum.IsDefined(typeof(ListItemType), itemType) && - itemType != ListItemType.Footer && - itemType != ListItemType.Header) - { - WebControl toDisplay = null; - if(ButtonType == ButtonColumnType.PushButton) - { - Button b = new Button(); - b.Text = Text; - b.CommandName = CommandName; - b.CausesValidation = false; - toDisplay = b; - } else - { - LinkButton lb = new DataGridLinkButton(); - lb.Text = Text; - lb.CommandName = CommandName; - lb.CausesValidation = false; - toDisplay = lb; - } - if(DataTextField.Length > 0) - { - toDisplay.DataBinding += new EventHandler(OnDataBindButtonColumn); - } - cell.Controls.Add(toDisplay); - } - } - - private void OnDataBindButtonColumn(object sender, EventArgs e) - { - Control ctrl = (Control)sender; - object item = ((DataGridItem)ctrl.NamingContainer).DataItem; - if(textFieldDescriptor == null) - { - textFieldDescriptor = TypeDescriptor.GetProperties(item).Find(DataTextField, true); - if(textFieldDescriptor == null && !DesignMode) - throw new HttpException(HttpRuntime.FormatResourceString("Field_Not_Found", DataTextField)); - } - string text; - if(textFieldDescriptor != null) - { - text = FormatDataTextValue(textFieldDescriptor.GetValue(item)); - } else - { - text = "Sample_DataBound_Text"; - } - if(ctrl is LinkButton) - { - ((LinkButton)ctrl).Text = text; - } - else - { - ((Button)ctrl).Text = text; - } - } - - protected virtual string FormatDataTextValue(object dataTextValue) - { - string retVal = null; - if(dataTextValue != null) - { - if(DataTextFormatString.Length > 0) - { - retVal = String.Format(DataTextFormatString, dataTextValue); - } - else - { - retVal = dataTextValue.ToString(); - } - } - return retVal; + +using System.ComponentModel; +using System.Security.Permissions; + +namespace System.Web.UI.WebControls +{ + // CAS + [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] + [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] + public class ButtonColumn : DataGridColumn + { + string text_field; + string format; + + [DefaultValue(ButtonColumnType.LinkButton)] + [WebSysDescription("The type of button contained within the column.")] + [WebCategory ("Misc")] + public virtual ButtonColumnType ButtonType { + get { + return (ButtonColumnType) ViewState.GetInt ("LinkButton", + (int) ButtonColumnType.LinkButton); + } + set { ViewState ["LinkButton"] = value; } + } + + [DefaultValue("")] + [WebSysDescription("The command associated with the button.")] + [WebCategory ("Misc")] + public virtual string CommandName { + get { return ViewState.GetString ("CommandName", String.Empty); } + set { ViewState ["CommandName"] = value; } + } + + [DefaultValue (false)] + [WebSysDescription("")] + [WebCategory ("Behavior")] + public virtual bool CausesValidation { + get { return ViewState.GetBool ("CausesValidation", false); } + set { ViewState ["CausesValidation"] = value; } + } + + [DefaultValue("")] + [WebSysDescription("The field bound to the text property of the button.")] + [WebCategory ("Misc")] + public virtual string DataTextField { + get { return ViewState.GetString ("DataTextField", String.Empty); } + set { ViewState ["DataTextField"] = value; } + } + + [DefaultValue("")] + [WebSysDescription("The formatting applied to the value bound to the Text property.")] + [WebCategory ("Misc")] + public virtual string DataTextFormatString { + get { return ViewState.GetString ("DataTextFormatString", String.Empty); } + set { + ViewState ["DataTextFormatString"] = value; + format = null; + } + } + + [DefaultValue("")] + [Localizable (true)] + [WebSysDescription("The text used for the button.")] + [WebCategory ("Misc")] + public virtual string Text { + get { return ViewState.GetString ("Text", String.Empty); } + set { ViewState ["Text"] = value; } + } + + [DefaultValue ("")] + [WebSysDescription("")] + [WebCategory ("Behavior")] + public virtual string ValidationGroup { + get { return ViewState.GetString ("ValidationGroup", String.Empty); } + set { ViewState ["ValidationGroup"] = value; } + } + + public override void Initialize () + { + /* No documentation for this method, so it's + * only here to keep corcompare quiet + */ + base.Initialize (); + } + + public override void InitializeCell (TableCell cell, int columnIndex, ListItemType itemType) + { + base.InitializeCell (cell, columnIndex, itemType); + + if (itemType != ListItemType.Header && itemType != ListItemType.Footer) { + switch (ButtonType) { + case ButtonColumnType.LinkButton: + { + LinkButton butt = new ForeColorLinkButton (); + + butt.Text = Text; + butt.CommandName = CommandName; + + if (!String.IsNullOrEmpty (DataTextField)) + butt.DataBinding += new EventHandler (DoDataBind); + + cell.Controls.Add (butt); + } + break; + + case ButtonColumnType.PushButton: + { + Button butt = new Button (); + + butt.Text = Text; + butt.CommandName = CommandName; + + if (!String.IsNullOrEmpty (DataTextField)) + butt.DataBinding += new EventHandler (DoDataBind); + cell.Controls.Add (butt); + } + break; + + } + } + } + + string GetValueFromItem (DataGridItem item) + { + object val = null; + if (text_field == null) + text_field = DataTextField; + + if (!String.IsNullOrEmpty (text_field)) + val = DataBinder.Eval (item.DataItem, text_field); + + return FormatDataTextValue (val); + } + + void DoDataBind (object sender, EventArgs e) + { + Control ctrl = (Control) sender; + string text = GetValueFromItem ((DataGridItem) ctrl.NamingContainer); + + LinkButton lb = sender as LinkButton; + if (lb == null) { + Button b = (Button) sender; + b.Text = text; + } else + lb.Text = text; + } + + protected virtual string FormatDataTextValue (object dataTextValue) + { + if (dataTextValue == null) + return String.Empty; + + if (format == null) + format = DataTextFormatString; + + if (String.IsNullOrEmpty (format)) + return dataTextValue.ToString (); + + return String.Format (format, dataTextValue); } + } +} - // LAMESPEC The framework uses Description values for metadata here. However they should be WebSysDescriptions - // because all metadata in this namespace has WebSysDescriptions - - [DefaultValue (typeof (ButtonColumnType), "LinkButton"), WebCategory ("Misc")] - [Description ("The type of button used in this column.")] - public virtual ButtonColumnType ButtonType - { - get - { - object o = ViewState["ButtonType"]; - if(o!=null) - return (ButtonColumnType)o; - return ButtonColumnType.LinkButton; - } - set - { - if(!System.Enum.IsDefined(typeof(ButtonColumnType), value)) - throw new ArgumentException(); - ViewState["ButtonType"] = value; - } - } - - [DefaultValue (""), WebCategory ("Misc")] - [Description ("The command assigned to this column.")] - public virtual string CommandName - { - get - { - string cn = (string)ViewState["CommandName"]; - if(cn!=null) - return cn; - return String.Empty; - } - set - { - ViewState["CommandName"] = value; - } - } - - [DefaultValue (""), WebCategory ("Misc")] - [Description ("The datafield that is bound to the text property.")] - public virtual string DataTextField - { - get - { - string dtf = (string)ViewState["DataTextField"]; - if(dtf!=null) - return dtf; - return String.Empty; - } - set - { - ViewState["DataTextField"] = value; - } - } - - [DefaultValue (""), WebCategory ("Misc")] - [Description ("A format that is applied to the bound text property.")] - public virtual string DataTextFormatString - { - get - { - string dtfs = (string)ViewState["DataTextFormatString"]; - if(dtfs!=null) - return dtfs; - return String.Empty; - } - set - { - ViewState["DataTextFormatString"] = value; - } - } - - [DefaultValue (""), WebCategory ("Misc")] - [Description ("The text used for this button.")] - public virtual string Text - { - get - { - string text = (string)ViewState["Text"]; - if(text!=null) - return text; - return String.Empty; - } - set - { - ViewState["Text"] = value; - } - } - } -}