System.Web.UI.WebControls.ButtonField.CommandName Property

Gets or sets a string that represents the action to perform when a button in a System.Web.UI.WebControls.ButtonField object is clicked.

Syntax

[System.ComponentModel.DefaultValue("")]
public virtual string CommandName { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

Use the ButtonField.CommandName property to associate a command name, such as "Add" or "Remove", with the buttons in the System.Web.UI.WebControls.ButtonField object. You can set the ButtonField.CommandName property to any string that identifies the action to perform when the command button is clicked. You can then programmatically determine the command name in an event handler and perform the appropriate actions.

Note:

All buttons in a System.Web.UI.WebControls.ButtonField object share the same command name.

Data-bound controls recognize certain command names and automatically raise and handle the appropriate events for the control. The following command names are recognized:

  • "Cancel"

  • "Delete"

  • "Edit"

  • "Insert"

  • "New"

  • "Page"

  • "Select"

  • "Sort"

  • "Update"

To invoke paging, set the ButtonField.CommandName to "Page" and the Button.CommandArgument of the contained System.Web.UI.WebControls.Button control to "First", "Last", "Prev", "Next", or a page number. However, since the Button.CommandArgument for a System.Web.UI.WebControls.ButtonField control is always the integer row index, a System.Web.UI.WebControls.ButtonField control is not suitable for invoking paging. Similarly, while you can invoke sorting by setting the ButtonField.CommandName to "Sort", the Button.CommandArgument property for a System.Web.UI.WebControls.ButtonField control is always the integer row index. For this reason, a System.Web.UI.WebControls.ButtonField control is not suitable for invoking sorting. For custom command names, such as "Add" and "Remove", you need to write the event code to check the command name and perform some custom action. For more information, see System.Web.UI.WebControls.DataControlCommands.

Note:

Not all command names are recognized by every data-bound controls. For example, "New" is not recognized by the System.Web.UI.WebControls.GridView control and "Select" is not recognized by the System.Web.UI.WebControls.DetailsView control.

The value of this property is stored in view state.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0