This documentation is archived and is not being maintained.

EditCommandColumn Class

A special column type for the DataGrid control that contains the Edit buttons for editing data items in each row.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class EditCommandColumn : public DataGridColumn

Use the EditCommandColumn class to create a special column for the DataGrid control that contains the Edit, Update, and Cancel buttons for each data row in the grid. These buttons allow you to edit the values of a row in the DataGrid control.

If no row is selected, an Edit button displays in the EditCommandColumn object for each data row in the DataGrid control. When the Edit button for an item is clicked, the EditCommand event is raised and the Edit button is replaced with the Update and Cancel buttons. You need to provide code to handle the EditCommand event. A typical event handler sets the EditItemIndex property to the selected row, and then rebinds the data to the DataGrid control.

NoteNote:

You must provide values for the CancelText, EditText, and UpdateText properties. Otherwise, the associated buttons will not appear in the EditCommandColumn.

The buttons in the EditCommandColumn can be set to display as hyperlinks or push buttons by setting the ButtonType property.

Clicking the Update or Cancel button raises the UpdateCommand or CancelCommand event, respectively. You need to provide code to handle these events.

A typical handler for the UpdateCommand event updates the data, sets the EditItemIndex property to -1 (to deselect the item), and then rebinds the data to the DataGrid control.

A typical handler for the CancelCommand event sets the EditItemIndex property to -1 (to deselect the item), and then rebinds the data to the DataGrid control.

Caution noteCaution:

The EditCommandColumn object can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a DataGrid control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.

By default, page validation is performed when an Update button in the EditCommandColumn control is clicked. Page validation determines whether the input controls that are associated with a validation control on the page all pass the validation rules that are specified by the validation control. To prevent page validation from occurring, set the CausesValidation property to false.

The following code example demonstrates how to add an EditCommandColumn object to a DataGrid control.

No code example is currently available or this language may not be supported.

System::Object
  System.Web.UI.WebControls::DataGridColumn
    System.Web.UI.WebControls::EditCommandColumn

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: