ButtonField.CommandName Property
Assembly: System.Web (in system.web.dll)
Use the CommandName property to associate a command name, such as "Add" or "Remove", with the buttons in the ButtonField object. You can set the 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 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 CommandName to "Page" and the CommandArgument of the contained Button control to "First", "Last", "Prev", "Next", or a page number. However, since the CommandArgument for a ButtonField control is always the integer row index, a ButtonField control is not suitable for invoking paging. Similarly, while you can invoke sorting by setting the CommandName to "Sort", the CommandArgument property for a ButtonField control is always the integer row index. For this reason, a 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 DataControlCommands.
Note |
|---|
| Not all command names are recognized by every data-bound controls. For example, "New" is not recognized by the GridView control and "Select" is not recognized by the DetailsView control. |
The value of this property is stored in view state.
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note