Skip to main content
A newer version of this page is available. .

Command Columns

  • 2 minutes to read

End-users manipulate ASPxGridView data using command columns. ASPxGridView stores command columns together with its data columns within the ASPxGridView.Columns collection.

Commands

A command column is represented by the GridViewCommandColumn class. It provides a set of commands that allow end-users to switch ASPxGridView to edit mode, and update data, delete rows, etc.

A command column allows multiple command items to be displayed within a cell. A single command is represented by a command item. There are eight command items.

Command Description Property
New Creates a new data row. ASPxGridViewCommandButtonSettings.NewButton
Edit Switches ASPxGridView to an edit mode. ASPxGridViewCommandButtonSettings.EditButton
Delete Deletes the current data row. ASPxGridViewCommandButtonSettings.DeleteButton
Select Selects/deselects data rows. ASPxGridViewCommandButtonSettings.SelectButton, GridViewCommandColumn.ShowSelectCheckbox
Update Saves all the changes made to the current data row and switches ASPxGridView to a browse mode. ASPxGridViewCommandButtonSettings.UpdateButton
Cancel Discards any changes made to the current data row and switches ASPxGridView to a browse mode. ASPxGridViewCommandButtonSettings.CancelButton
Clear Clears the filter expression applied to ASPxGridView. ASPxGridViewCommandButtonSettings.ClearFilterButton
Recover Recovers a deleted data row. ASPxGridViewCommandButtonSettings.RecoverButton

By default, command items are represented by a link. They can also be represented by a button or image. Use the GridViewCommandColumn.ButtonType property to specify how the command column renders its command items.

To initialize individual command buttons, handle the ASPxGridView.CommandButtonInitialize event.

Behavior

End-users can move command columns among visible columns or to the Customization Window by dragging their headers. This is controlled by the column’s GridViewCommandColumn.AllowDragDrop property. If this property is set to Default, the column’s behavior is controlled by ASPxGridView’s ASPxGridViewBehaviorSettings.AllowDragDrop option.

Custom Buttons

Command columns can also display custom buttons within command cells or filter. You can create your own buttons, and define custom actions for them. For example, see How to: Create Custom Command Buttons.

This example shows how to create and initialize a command column with custom command buttons at runtime.

using DevExpress.Web.ASPxGridView;

protected void Page_Load(object sender, EventArgs e) {
    if (!IsPostBack) {
        // Creates and initializes a command column.
        GridViewCommandColumn commandCol = new GridViewCommandColumn("Action");
        commandCol.Name = "Action";
        ASPxGridView1.Columns.Add(commandCol);
    }
    // Creates a custom command button.
    (ASPxGridView1.Columns["Action"] 
    as GridViewCommandColumn).CustomButtons.Add(CreateCustomButton());
}

GridViewCommandColumnCustomButton CreateCustomButton() {
    GridViewCommandColumnCustomButton customBtn = new GridViewCommandColumnCustomButton();
    customBtn.ID = "action1";
    customBtn.Text = "Action1";
    customBtn.Visibility = GridViewCustomButtonVisibility.BrowsableRow;
    return customBtn;
}
// Occurs after a command button has been clicked.
protected void ASPxGridView1_CustomButtonCallback(object sender,
ASPxGridViewCustomButtonCallbackEventArgs e) {
    if (e.ButtonID == "action1") {
        // ...
    }
}

To initialize individual custom command buttons, handle the ASPxGridView.CustomButtonInitialize event.