Back to Devexpress

ASPxGridView.CellEditorInitialize Event

aspnet-devexpress-dot-web-dot-aspxgridview-7d6d0852.md

latest3.7 KB
Original Source

ASPxGridView.CellEditorInitialize Event

Occurs after a cell editor contained in the edit cells is initialized, but before it’s shown.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxGridViewEditorEventHandler CellEditorInitialize
vb
Public Event CellEditorInitialize As ASPxGridViewEditorEventHandler

Event Data

The CellEditorInitialize event's data class is ASPxGridViewEditorEventArgs. The following properties provide information specific to this event:

PropertyDescription
ColumnGets the data column whose cell editor is being initialized.
EditorGets the editor currently being processed. Inherited from ASPxGridEditorEventArgs.
KeyValueGets the row key value - an object that uniquely identifies the row.
ValueGets the editor’s value. Inherited from ASPxGridEditorEventArgs.
VisibleIndexGets the edited row’s visible index.

Remarks

When the Grid switches a row to edit mode, it sends a callback request to the server to initialize cell editors. Handle the CellEditorInitialize event to customize an editor’s settings before it is shown in the edit cell.

The CellEditorInitialize event is raised when an editor is created. The control hierarchy can be recreated several times during a request. As the result of the hierarchy recreation, the editor is also recreated, and this event can be raised several times.

Example 1

The following code sample demonstrates how to focus a column’s editor when it is initialized:

csharp
protected void ASPxGridView1_CellEditorInitialize(object sender,
    DevExpress.Web.ASPxGridViewEditorEventArgs e) {
    if (e.Column.FieldName == "TimeFrom") {
        e.Editor.Focus();
    }
};

Example 2

The following code sample demonstrates how to prevent a user from changing the unit price.

csharp
protected void ASPxGridView1_CellEditorInitialize(object sender,
    DevExpress.Web.ASPxGridViewEditorEventArgs e) {
    if (ASPxGridView1.IsNewRowEditing) return;
    if (e.Column.FieldName == "UnitPrice")
        e.Editor.ReadOnly = true;
}

Limitations

  • The CellEditorInitialize event does not fire in Batch edit mode because in this mode, requests are not sent to the server when an editor is activated.
  • The CellEditorInitialize event affects only the grid edit mode settings (when editors are visible).
  • The CellEditorInitialize event fires only for built-in column editors and does not fire for custom editors defined in templates.

See Also

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace