Tuesday, 3 January 2012

DevExpress AspxGridview - Disable/Hide edit button based on column values

The following will allow the disabling/hiding of an edit button on an AspxGridview based on the value in one of the fields. In this snippet, it checks to see if the rowValue value is populated and if so, it will disable editing
Protected Sub GridSigners_CommandButtonInitialize(sender As Object, e As DevExpress.Web.ASPxGridView.ASPxGridViewCommandButtonEventArgs) Handles GridSigners.CommandButtonInitialize
 
        
If e.Button.ButtonType = DevExpress.Web.ASPxGridView.ColumnCommandButtonType.Edit Then
           
Dim rowValue As Object = DirectCast(sender, ASPxGridView).GetRowValues(e.VisibleIndex, "columnName")
                If (rowValue Is DBNull.Value) Then
                    e.Visible = True
                Else
                    e.Visible = False
                End If
End If

1 comment: