A special column type for the System.Web.UI.WebControls.DataGrid control that contains the Edit buttons for editing data items in each row.
See Also: EditCommandColumn Members
Use the System.Web.UI.WebControls.EditCommandColumn class to create a special column for the System.Web.UI.WebControls.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 System.Web.UI.WebControls.DataGrid control.
If no row is selected, an Edit button displays in the System.Web.UI.WebControls.EditCommandColumn object for each data row in the System.Web.UI.WebControls.DataGrid control. When the Edit button for an item is clicked, the DataGrid.EditCommand event is raised and the Edit button is replaced with the Update and Cancel buttons. You need to provide code to handle the DataGrid.EditCommand event. A typical event handler sets the DataGrid.EditItemIndex property to the selected row, and then rebinds the data to the System.Web.UI.WebControls.DataGrid control.
You must provide values for the EditCommandColumn.CancelText, EditCommandColumn.EditText, and EditCommandColumn.UpdateText properties. Otherwise, the associated buttons will not appear in the System.Web.UI.WebControls.EditCommandColumn.
The buttons in the System.Web.UI.WebControls.EditCommandColumn can be set to display as hyperlinks or push buttons by setting the EditCommandColumn.ButtonType property.
Clicking the Update or Cancel button raises the DataGrid.UpdateCommand or DataGrid.CancelCommand event, respectively. You need to provide code to handle these events.
A typical handler for the DataGrid.UpdateCommand event updates the data, sets the DataGrid.EditItemIndex property to -1 (to deselect the item), and then rebinds the data to the System.Web.UI.WebControls.DataGrid control.
A typical handler for the DataGrid.CancelCommand event sets the DataGrid.EditItemIndex property to -1 (to deselect the item), and then rebinds the data to the System.Web.UI.WebControls.DataGrid control.
The System.Web.UI.WebControls.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 System.Web.UI.WebControls.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 System.Web.UI.WebControls.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 EditCommandColumn.CausesValidation property to false.