Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebControls / CommandField.cs / 1305376 / CommandField.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Drawing.Design; using System.Globalization; ////// public class CommandField : ButtonFieldBase { ///Creates a special field with buttons for ///, /// , and commands to edit items /// within the selected row. /// public CommandField() { } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_CancelImageUrl), UrlProperty() ] public virtual string CancelImageUrl { get { object o = ViewState["CancelImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["CancelImageUrl"])) { ViewState["CancelImageUrl"] = value; OnFieldChanged(); } } } ///Initializes a new instance of an ///class. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultCancelCaption), WebSysDescription(SR.CommandField_CancelText) ] public virtual string CancelText { get { object text = ViewState["CancelText"]; return text == null ? SR.GetString(SR.CommandField_DefaultCancelCaption) : (string)text; } set { if (!String.Equals(value, ViewState["CancelText"])) { ViewState["CancelText"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.ButtonFieldBase_CausesValidation) ] public override bool CausesValidation { get { object o = ViewState["CausesValidation"]; if (o != null) { return (bool)o; } return true; } set { base.CausesValidation = value; } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_DeleteImageUrl), UrlProperty() ] public virtual string DeleteImageUrl { get { object o = ViewState["DeleteImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["DeleteImageUrl"])) { ViewState["DeleteImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultDeleteCaption), WebSysDescription(SR.CommandField_DeleteText) ] public virtual string DeleteText { get { object text = ViewState["DeleteText"]; return text == null ? SR.GetString(SR.CommandField_DefaultDeleteCaption) : (string)text; } set { if (!String.Equals(value, ViewState["DeleteText"])) { ViewState["DeleteText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_EditImageUrl), UrlProperty() ] public virtual string EditImageUrl { get { object o = ViewState["EditImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["EditImageUrl"])) { ViewState["EditImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button in /// the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultEditCaption), WebSysDescription(SR.CommandField_EditText) ] public virtual string EditText { get { object text = ViewState["EditText"]; return text == null ? SR.GetString(SR.CommandField_DefaultEditCaption) : (string)text; } set { if (!String.Equals(value, ViewState["EditText"])) { ViewState["EditText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_InsertImageUrl), UrlProperty() ] public virtual string InsertImageUrl { get { object o = ViewState["InsertImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["InsertImageUrl"])) { ViewState["InsertImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button in /// the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultInsertCaption), WebSysDescription(SR.CommandField_InsertText) ] public virtual string InsertText { get { object text = ViewState["InsertText"]; return text == null ? SR.GetString(SR.CommandField_DefaultInsertCaption) : (string)text; } set { if (!String.Equals(value, ViewState["InsertText"])) { ViewState["InsertText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_NewImageUrl), UrlProperty() ] public virtual string NewImageUrl { get { object o = ViewState["NewImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["NewImageUrl"])) { ViewState["NewImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultNewCaption), WebSysDescription(SR.CommandField_NewText) ] public virtual string NewText { get { object text = ViewState["NewText"]; return text == null ? SR.GetString(SR.CommandField_DefaultNewCaption) : (string)text; } set { if (!String.Equals(value, ViewState["NewText"])) { ViewState["NewText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_SelectImageUrl), UrlProperty() ] public virtual string SelectImageUrl { get { object o = ViewState["SelectImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["SelectImageUrl"])) { ViewState["SelectImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultSelectCaption), WebSysDescription(SR.CommandField_SelectText) ] public virtual string SelectText { get { object text = ViewState["SelectText"]; return text == null ? SR.GetString(SR.CommandField_DefaultSelectCaption) : (string)text; } set { if (!String.Equals(value, ViewState["SelectText"])) { ViewState["SelectText"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.CommandField_ShowCancelButton) ] public virtual bool ShowCancelButton { get { object o = ViewState["ShowCancelButton"]; if (o != null) { return (bool)o; } return true; } set { object oldValue = ViewState["ShowCancelButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowCancelButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowDeleteButton) ] public virtual bool ShowDeleteButton { get { object o = ViewState["ShowDeleteButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowDeleteButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowDeleteButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowEditButton) ] public virtual bool ShowEditButton { get { object o = ViewState["ShowEditButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowEditButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowEditButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowSelectButton) ] public virtual bool ShowSelectButton { get { object o = ViewState["ShowSelectButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowSelectButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowSelectButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowInsertButton) ] public virtual bool ShowInsertButton { get { object o = ViewState["ShowInsertButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowInsertButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowInsertButton"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_UpdateImageUrl), UrlProperty() ] public virtual string UpdateImageUrl { get { object o = ViewState["UpdateImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["UpdateImageUrl"])) { ViewState["UpdateImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultUpdateCaption), WebSysDescription(SR.CommandField_UpdateText) ] public virtual string UpdateText { get { object text = ViewState["UpdateText"]; return text == null ? SR.GetString(SR.CommandField_DefaultUpdateCaption) : (string)text; } set { if (!String.Equals(value, ViewState["UpdateText"])) { ViewState["UpdateText"] = value; OnFieldChanged(); } } } private void AddButtonToCell(DataControlFieldCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl) { IButtonControl button; IPostBackContainer container = Control as IPostBackContainer; bool setCausesValidation = true; // the setter on the DataControlButtons throw if there's a container for security switch (ButtonType) { case ButtonType.Link: { if (container != null && !causesValidation) { button = new DataControlLinkButton(container); setCausesValidation = false; } else { button = new DataControlLinkButton(null); } break; } case ButtonType.Button: { if (container != null && !causesValidation) { button = new DataControlButton(container); setCausesValidation = false; } else { button = new Button(); } break; } case ButtonType.Image: default: { if (container != null && !causesValidation) { button = new DataControlImageButton(container); setCausesValidation = false; } else { button = new ImageButton(); } ((ImageButton)button).ImageUrl = imageUrl; break; } } button.Text = buttonText; button.CommandName = commandName; button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture); if (setCausesValidation) { button.CausesValidation = causesValidation; } button.ValidationGroup = validationGroup; cell.Controls.Add((WebControl)button); } protected override void CopyProperties(DataControlField newField) { ((CommandField)newField).CancelImageUrl = CancelImageUrl; ((CommandField)newField).CancelText = CancelText; ((CommandField)newField).DeleteImageUrl = DeleteImageUrl; ((CommandField)newField).DeleteText = DeleteText; ((CommandField)newField).EditImageUrl = EditImageUrl; ((CommandField)newField).EditText = EditText; ((CommandField)newField).InsertImageUrl = InsertImageUrl; ((CommandField)newField).InsertText = InsertText; ((CommandField)newField).NewImageUrl = NewImageUrl; ((CommandField)newField).NewText = NewText; ((CommandField)newField).SelectImageUrl = SelectImageUrl; ((CommandField)newField).SelectText = SelectText; ((CommandField)newField).UpdateImageUrl = UpdateImageUrl; ((CommandField)newField).UpdateText = UpdateText; ((CommandField)newField).ShowCancelButton = ShowCancelButton; ((CommandField)newField).ShowDeleteButton = ShowDeleteButton; ((CommandField)newField).ShowEditButton = ShowEditButton; ((CommandField)newField).ShowSelectButton = ShowSelectButton; ((CommandField)newField).ShowInsertButton = ShowInsertButton; base.CopyProperties(newField); } protected override DataControlField CreateField() { return new CommandField(); } ///Indicates the text to display for the ///command button /// in the field. /// public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { base.InitializeCell(cell, cellType, rowState, rowIndex); bool showEditButton = ShowEditButton; bool showDeleteButton = ShowDeleteButton; bool showInsertButton = ShowInsertButton; bool showSelectButton = ShowSelectButton; bool showCancelButton = ShowCancelButton; bool isFirstButton = true; bool causesValidation = CausesValidation; string validationGroup = ValidationGroup; LiteralControl spaceControl; if (cellType == DataControlCellType.DataCell) { if ((rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0) { if ((rowState & DataControlRowState.Edit) != 0 && showEditButton) { AddButtonToCell(cell, DataControlCommands.UpdateCommandName, UpdateText, causesValidation, validationGroup, rowIndex, UpdateImageUrl); if (showCancelButton) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); AddButtonToCell(cell, DataControlCommands.CancelCommandName, CancelText, false, String.Empty, rowIndex, CancelImageUrl); } } if ((rowState & DataControlRowState.Insert) != 0 && showInsertButton) { AddButtonToCell(cell, DataControlCommands.InsertCommandName, InsertText, causesValidation, validationGroup, rowIndex, InsertImageUrl); if (showCancelButton) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); AddButtonToCell(cell, DataControlCommands.CancelCommandName, CancelText, false, String.Empty, rowIndex, CancelImageUrl); } } } else { if (showEditButton) { AddButtonToCell(cell, DataControlCommands.EditCommandName, EditText, false, String.Empty, rowIndex, EditImageUrl); isFirstButton = false; } if (showDeleteButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.DeleteCommandName, DeleteText, false, String.Empty, rowIndex, DeleteImageUrl); isFirstButton = false; } if (showInsertButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.NewCommandName, NewText, false, String.Empty, rowIndex, NewImageUrl); isFirstButton = false; } if (showSelectButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.SelectCommandName, SelectText, false, String.Empty, rowIndex, SelectImageUrl); isFirstButton = false; } } } } ///Initializes a cell within the field. ////// public override void ValidateSupportsCallback() { if (ShowSelectButton) { throw new NotSupportedException(SR.GetString(SR.CommandField_CallbacksNotSupported, Control.ID)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //Override with an empty body if the field's controls all support callback. /// Otherwise, override and throw a useful error message about why the field can't support callbacks. ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls { using System; using System.Collections; using System.ComponentModel; using System.Drawing.Design; using System.Globalization; ////// public class CommandField : ButtonFieldBase { ///Creates a special field with buttons for ///, /// , and commands to edit items /// within the selected row. /// public CommandField() { } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_CancelImageUrl), UrlProperty() ] public virtual string CancelImageUrl { get { object o = ViewState["CancelImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["CancelImageUrl"])) { ViewState["CancelImageUrl"] = value; OnFieldChanged(); } } } ///Initializes a new instance of an ///class. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultCancelCaption), WebSysDescription(SR.CommandField_CancelText) ] public virtual string CancelText { get { object text = ViewState["CancelText"]; return text == null ? SR.GetString(SR.CommandField_DefaultCancelCaption) : (string)text; } set { if (!String.Equals(value, ViewState["CancelText"])) { ViewState["CancelText"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.ButtonFieldBase_CausesValidation) ] public override bool CausesValidation { get { object o = ViewState["CausesValidation"]; if (o != null) { return (bool)o; } return true; } set { base.CausesValidation = value; } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_DeleteImageUrl), UrlProperty() ] public virtual string DeleteImageUrl { get { object o = ViewState["DeleteImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["DeleteImageUrl"])) { ViewState["DeleteImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultDeleteCaption), WebSysDescription(SR.CommandField_DeleteText) ] public virtual string DeleteText { get { object text = ViewState["DeleteText"]; return text == null ? SR.GetString(SR.CommandField_DefaultDeleteCaption) : (string)text; } set { if (!String.Equals(value, ViewState["DeleteText"])) { ViewState["DeleteText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_EditImageUrl), UrlProperty() ] public virtual string EditImageUrl { get { object o = ViewState["EditImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["EditImageUrl"])) { ViewState["EditImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button in /// the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultEditCaption), WebSysDescription(SR.CommandField_EditText) ] public virtual string EditText { get { object text = ViewState["EditText"]; return text == null ? SR.GetString(SR.CommandField_DefaultEditCaption) : (string)text; } set { if (!String.Equals(value, ViewState["EditText"])) { ViewState["EditText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_InsertImageUrl), UrlProperty() ] public virtual string InsertImageUrl { get { object o = ViewState["InsertImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["InsertImageUrl"])) { ViewState["InsertImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button in /// the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultInsertCaption), WebSysDescription(SR.CommandField_InsertText) ] public virtual string InsertText { get { object text = ViewState["InsertText"]; return text == null ? SR.GetString(SR.CommandField_DefaultInsertCaption) : (string)text; } set { if (!String.Equals(value, ViewState["InsertText"])) { ViewState["InsertText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_NewImageUrl), UrlProperty() ] public virtual string NewImageUrl { get { object o = ViewState["NewImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["NewImageUrl"])) { ViewState["NewImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultNewCaption), WebSysDescription(SR.CommandField_NewText) ] public virtual string NewText { get { object text = ViewState["NewText"]; return text == null ? SR.GetString(SR.CommandField_DefaultNewCaption) : (string)text; } set { if (!String.Equals(value, ViewState["NewText"])) { ViewState["NewText"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_SelectImageUrl), UrlProperty() ] public virtual string SelectImageUrl { get { object o = ViewState["SelectImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["SelectImageUrl"])) { ViewState["SelectImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultSelectCaption), WebSysDescription(SR.CommandField_SelectText) ] public virtual string SelectText { get { object text = ViewState["SelectText"]; return text == null ? SR.GetString(SR.CommandField_DefaultSelectCaption) : (string)text; } set { if (!String.Equals(value, ViewState["SelectText"])) { ViewState["SelectText"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(true), WebSysDescription(SR.CommandField_ShowCancelButton) ] public virtual bool ShowCancelButton { get { object o = ViewState["ShowCancelButton"]; if (o != null) { return (bool)o; } return true; } set { object oldValue = ViewState["ShowCancelButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowCancelButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowDeleteButton) ] public virtual bool ShowDeleteButton { get { object o = ViewState["ShowDeleteButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowDeleteButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowDeleteButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowEditButton) ] public virtual bool ShowEditButton { get { object o = ViewState["ShowEditButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowEditButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowEditButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowSelectButton) ] public virtual bool ShowSelectButton { get { object o = ViewState["ShowSelectButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowSelectButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowSelectButton"] = value; OnFieldChanged(); } } } [ WebCategory("Behavior"), DefaultValue(false), WebSysDescription(SR.CommandField_ShowInsertButton) ] public virtual bool ShowInsertButton { get { object o = ViewState["ShowInsertButton"]; if (o != null) { return (bool)o; } return false; } set { object oldValue = ViewState["ShowInsertButton"]; if (oldValue == null || (bool)oldValue != value) { ViewState["ShowInsertButton"] = value; OnFieldChanged(); } } } [ WebCategory("Appearance"), DefaultValue(""), Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)), WebSysDescription(SR.CommandField_UpdateImageUrl), UrlProperty() ] public virtual string UpdateImageUrl { get { object o = ViewState["UpdateImageUrl"]; if (o != null) { return (string)o; } return String.Empty; } set { if (!String.Equals(value, ViewState["UpdateImageUrl"])) { ViewState["UpdateImageUrl"] = value; OnFieldChanged(); } } } ///Indicates the text to display for the ///command button /// in the field. /// [ WebCategory("Appearance"), Localizable(true), WebSysDefaultValue(SR.CommandField_DefaultUpdateCaption), WebSysDescription(SR.CommandField_UpdateText) ] public virtual string UpdateText { get { object text = ViewState["UpdateText"]; return text == null ? SR.GetString(SR.CommandField_DefaultUpdateCaption) : (string)text; } set { if (!String.Equals(value, ViewState["UpdateText"])) { ViewState["UpdateText"] = value; OnFieldChanged(); } } } private void AddButtonToCell(DataControlFieldCell cell, string commandName, string buttonText, bool causesValidation, string validationGroup, int rowIndex, string imageUrl) { IButtonControl button; IPostBackContainer container = Control as IPostBackContainer; bool setCausesValidation = true; // the setter on the DataControlButtons throw if there's a container for security switch (ButtonType) { case ButtonType.Link: { if (container != null && !causesValidation) { button = new DataControlLinkButton(container); setCausesValidation = false; } else { button = new DataControlLinkButton(null); } break; } case ButtonType.Button: { if (container != null && !causesValidation) { button = new DataControlButton(container); setCausesValidation = false; } else { button = new Button(); } break; } case ButtonType.Image: default: { if (container != null && !causesValidation) { button = new DataControlImageButton(container); setCausesValidation = false; } else { button = new ImageButton(); } ((ImageButton)button).ImageUrl = imageUrl; break; } } button.Text = buttonText; button.CommandName = commandName; button.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture); if (setCausesValidation) { button.CausesValidation = causesValidation; } button.ValidationGroup = validationGroup; cell.Controls.Add((WebControl)button); } protected override void CopyProperties(DataControlField newField) { ((CommandField)newField).CancelImageUrl = CancelImageUrl; ((CommandField)newField).CancelText = CancelText; ((CommandField)newField).DeleteImageUrl = DeleteImageUrl; ((CommandField)newField).DeleteText = DeleteText; ((CommandField)newField).EditImageUrl = EditImageUrl; ((CommandField)newField).EditText = EditText; ((CommandField)newField).InsertImageUrl = InsertImageUrl; ((CommandField)newField).InsertText = InsertText; ((CommandField)newField).NewImageUrl = NewImageUrl; ((CommandField)newField).NewText = NewText; ((CommandField)newField).SelectImageUrl = SelectImageUrl; ((CommandField)newField).SelectText = SelectText; ((CommandField)newField).UpdateImageUrl = UpdateImageUrl; ((CommandField)newField).UpdateText = UpdateText; ((CommandField)newField).ShowCancelButton = ShowCancelButton; ((CommandField)newField).ShowDeleteButton = ShowDeleteButton; ((CommandField)newField).ShowEditButton = ShowEditButton; ((CommandField)newField).ShowSelectButton = ShowSelectButton; ((CommandField)newField).ShowInsertButton = ShowInsertButton; base.CopyProperties(newField); } protected override DataControlField CreateField() { return new CommandField(); } ///Indicates the text to display for the ///command button /// in the field. /// public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { base.InitializeCell(cell, cellType, rowState, rowIndex); bool showEditButton = ShowEditButton; bool showDeleteButton = ShowDeleteButton; bool showInsertButton = ShowInsertButton; bool showSelectButton = ShowSelectButton; bool showCancelButton = ShowCancelButton; bool isFirstButton = true; bool causesValidation = CausesValidation; string validationGroup = ValidationGroup; LiteralControl spaceControl; if (cellType == DataControlCellType.DataCell) { if ((rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0) { if ((rowState & DataControlRowState.Edit) != 0 && showEditButton) { AddButtonToCell(cell, DataControlCommands.UpdateCommandName, UpdateText, causesValidation, validationGroup, rowIndex, UpdateImageUrl); if (showCancelButton) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); AddButtonToCell(cell, DataControlCommands.CancelCommandName, CancelText, false, String.Empty, rowIndex, CancelImageUrl); } } if ((rowState & DataControlRowState.Insert) != 0 && showInsertButton) { AddButtonToCell(cell, DataControlCommands.InsertCommandName, InsertText, causesValidation, validationGroup, rowIndex, InsertImageUrl); if (showCancelButton) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); AddButtonToCell(cell, DataControlCommands.CancelCommandName, CancelText, false, String.Empty, rowIndex, CancelImageUrl); } } } else { if (showEditButton) { AddButtonToCell(cell, DataControlCommands.EditCommandName, EditText, false, String.Empty, rowIndex, EditImageUrl); isFirstButton = false; } if (showDeleteButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.DeleteCommandName, DeleteText, false, String.Empty, rowIndex, DeleteImageUrl); isFirstButton = false; } if (showInsertButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.NewCommandName, NewText, false, String.Empty, rowIndex, NewImageUrl); isFirstButton = false; } if (showSelectButton) { if (isFirstButton == false) { spaceControl = new LiteralControl(" "); cell.Controls.Add(spaceControl); } AddButtonToCell(cell, DataControlCommands.SelectCommandName, SelectText, false, String.Empty, rowIndex, SelectImageUrl); isFirstButton = false; } } } } ///Initializes a cell within the field. ////// public override void ValidateSupportsCallback() { if (ShowSelectButton) { throw new NotSupportedException(SR.GetString(SR.CommandField_CallbacksNotSupported, Control.ID)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.Override with an empty body if the field's controls all support callback. /// Otherwise, override and throw a useful error message about why the field can't support callbacks. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- GlyphInfoList.cs
- TextRangeProviderWrapper.cs
- PrintDocument.cs
- HScrollProperties.cs
- BamlLocalizableResource.cs
- BaseResourcesBuildProvider.cs
- InputBuffer.cs
- Setter.cs
- CommandSet.cs
- SecureStringHasher.cs
- Pair.cs
- ArrayElementGridEntry.cs
- BlockCollection.cs
- DefaultAssemblyResolver.cs
- MobileCapabilities.cs
- DataExpression.cs
- Registry.cs
- ScriptResourceInfo.cs
- EntityViewGenerator.cs
- ForwardPositionQuery.cs
- CodeBinaryOperatorExpression.cs
- AsyncOperationManager.cs
- Assert.cs
- AsymmetricAlgorithm.cs
- ContainerControlDesigner.cs
- EndpointConfigContainer.cs
- SourceInterpreter.cs
- DataViewSettingCollection.cs
- TextSpanModifier.cs
- Color.cs
- EmptyStringExpandableObjectConverter.cs
- PowerStatus.cs
- sqlnorm.cs
- AppDomainAttributes.cs
- XmlSchemaGroupRef.cs
- XmlHierarchicalEnumerable.cs
- TextRunTypographyProperties.cs
- TextServicesCompartmentContext.cs
- mda.cs
- Trace.cs
- Privilege.cs
- SqlTypeSystemProvider.cs
- AnnotationResourceChangedEventArgs.cs
- SQLInt64.cs
- SettingsProviderCollection.cs
- XmlValidatingReaderImpl.cs
- EmptyQuery.cs
- TablePatternIdentifiers.cs
- StringUtil.cs
- DynamicPhysicalDiscoSearcher.cs
- NumericUpDownAcceleration.cs
- SqlConnectionManager.cs
- SHA512Managed.cs
- Hash.cs
- BigInt.cs
- InternalConfigRoot.cs
- Selection.cs
- RoleGroupCollection.cs
- PriorityItem.cs
- ReadOnlyObservableCollection.cs
- QilFactory.cs
- MessagePropertyDescription.cs
- infer.cs
- EndOfStreamException.cs
- WeakKeyDictionary.cs
- TreeViewItem.cs
- Environment.cs
- ProcessModelSection.cs
- DbReferenceCollection.cs
- RoleManagerEventArgs.cs
- NumberSubstitution.cs
- DataGridViewSelectedRowCollection.cs
- MessageQueuePermission.cs
- ArithmeticException.cs
- SchemaNames.cs
- SafeViewOfFileHandle.cs
- EntityDataSourceChangedEventArgs.cs
- StylusDevice.cs
- GenericPrincipal.cs
- Registry.cs
- MailWriter.cs
- RowBinding.cs
- DataControlFieldCell.cs
- Metadata.cs
- FontCacheUtil.cs
- StorageModelBuildProvider.cs
- XmlMemberMapping.cs
- StorageInfo.cs
- ThemeDictionaryExtension.cs
- ControlIdConverter.cs
- Walker.cs
- ExternalFile.cs
- WindowsSysHeader.cs
- SwitchAttribute.cs
- DataGridViewRowCancelEventArgs.cs
- XmlILOptimizerVisitor.cs
- CompilerInfo.cs
- OutputWindow.cs
- BooleanToVisibilityConverter.cs
- FrugalList.cs