Back to Devexpress

ASPxGridView.StartRowEditing Event

aspnet-devexpress-dot-web-dot-aspxgridview-e413d27b.md

latest3.6 KB
Original Source

ASPxGridView.StartRowEditing Event

Enables you to prevent a row from being edited.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxStartRowEditingEventHandler StartRowEditing
vb
Public Event StartRowEditing As ASPxStartRowEditingEventHandler

Event Data

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

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
EditingKeyValueGets the processed row’s key value.

Remarks

The StartRowEditing event occurs when an end-user has clicked the Edit command or the ASPxGridView.StartEdit method has been called. To prevent switching the ASPxGridView to edit mode, set the event parameter’s Cancel property to true.

Example

The code sample below demonstrates how you can prohibit a user from editing data rows containing information unrelated to the Sales department.

csharp
string UserDepartment = "Sales";
...
protected void MyGridView_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) {
     if (MyGridView.GetRowValuesByKeyValue(e.EditingKeyValue, "Department").ToString() != UserDepartment) {
          e.Cancel = true;
     }
}
vb
Dim UserDepartment As String = "Sales"
...
Protected Sub MyGridView_StartRowEditing(sender As Object, e As DevExpress.Web.Data.ASPxStartRowEditingEventArgs)
    If MyGridView.GetRowValuesByKeyValue(e.EditingKeyValue, "Department").ToString() <> UserDepartment Then
        e.Cancel = True
    End If
End Sub
aspx
<dx:ASPxGridView ID="MyGridView" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
KeyFieldName="ID" OnStartRowEditing="MyGridView_StartRowEditing">
          <Columns>
          <dx:GridViewCommandColumn VisibleIndex="0">
                    <EditButton Visible="True">
                    </EditButton>
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="Department" ReadOnly="True" VisibleIndex="0">
          </dx:GridViewDataTextColumn>
          ...
          </Columns>
</dx:ASPxGridView>

See Also

GetRowValuesByKeyValue(Object, String[])

CommandButtonInitialize

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace