Back to Devexpress

ASPxCardView.CommandButtonInitialize Event

aspnet-devexpress-dot-web-dot-aspxcardview-651ba068.md

latest7.5 KB
Original Source

ASPxCardView.CommandButtonInitialize Event

Enables individual command buttons to be initialized.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event ASPxCardViewCommandButtonEventHandler CommandButtonInitialize
vb
Public Event CommandButtonInitialize As ASPxCardViewCommandButtonEventHandler

Event Data

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

PropertyDescription
ButtonTypeGets the type of the command button currently being initialized.
EnabledGets or sets whether the processed command button is enabled. Inherited from ASPxGridCommandButtonEventArgs.
ImageGets the settings of an image displayed within the processed command button. Inherited from ASPxGridCommandButtonEventArgs.
IsEditingCardGets whether a command button is displayed within the card currently being edited.
LayoutItemGets the command layout item which owns the processed command button.
RenderModeSpecifies the processed command button’s render mode. Inherited from ASPxGridCommandButtonEventArgs.
StylesGets the processed command button’s style. Inherited from ASPxGridCommandButtonEventArgs.
TextGets the processed command button’s text. Inherited from ASPxGridCommandButtonEventArgs.
VisibleGets or sets whether the command button is visible. Inherited from ASPxGridCommandButtonEventArgs.
VisibleIndexGets the visible index of a data item (row, card or record) which contains the processed command button. Inherited from ASPxGridCommandButtonEventArgs.

Remarks

The CommandButtonInitialize event is raised for each built-in command button (edit, new, delete, etc.), and allows their settings to be initialized. For instance, you can hide or disable individual command buttons.

The processed button is returned by the ASPxCardViewCommandButtonEventArgs.ButtonType property. The card in which this button is displayed can be identified by its visible index, returned by the ASPxGridCommandButtonEventArgs.VisibleIndex property. To specify whether the button should be visible or enabled, use the ASPxGridCommandButtonEventArgs.Visible and ASPxGridCommandButtonEventArgs.Enabled properties, respectively.

To initialize custom command buttons, handle the ASPxCardView.CustomButtonInitialize event.

Note

When Batch Edit Mode is enabled, the card view renders service cards with negative indices that are used to add new cards. These cards are hidden from end-users and are necessary for the correct operation of these features. In this case, the ASPxGridCommandButtonEventArgs.VisibleIndex parameter may have the “-2147483647” value in the CommandButtonInitialize event handler when a new card is being edited.

To process only the command buttons of the visible cards, use the following code in the CommandButtonInitialize event handler:

csharp
if(e.VisibleIndex >= 0){
 //custom actions
}

Example

The following example uses an external check box to change the visibility of ASPxCardView check boxes in multi-selection mode.

aspx
<dx:ASPxCheckBox ID="chkDisabled" runat="server" Text="Disable selection checkboxes"
    AutoPostBack="true" />

<dx:ASPxCardView ID="ASPxCardView1" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="CustomerID" OnCommandButtonInitialize="ASPxCardView1_CommandButtonInitialize" AutoGenerateColumns="False">
    <Columns>
        <dx:CardViewTextColumn FieldName="CompanyName" />
        <dx:CardViewTextColumn FieldName="ContactName" />
        <dx:CardViewTextColumn FieldName="City" />
        <dx:CardViewTextColumn FieldName="Region" />
        <dx:CardViewTextColumn FieldName="Country" />
    </Columns>
    <CardLayoutProperties>
        <Items>
            <dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowSelectCheckbox="True" />
            <dx:CardViewColumnLayoutItem ColumnName="Company Name" />
            <dx:CardViewColumnLayoutItem ColumnName="Contact Name" />
            <dx:CardViewColumnLayoutItem ColumnName="City" />
            <dx:CardViewColumnLayoutItem ColumnName="Region" />
            <dx:CardViewColumnLayoutItem ColumnName="Country" />
            <dx:EditModeCommandLayoutItem HorizontalAlign="Right" />
        </Items>
    </CardLayoutProperties>
</dx:ASPxCardView>  
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
    SelectCommand="SELECT * FROM [Customers]" />
csharp
protected void ASPxCardView1_CommandButtonInitialize(object sender, DevExpress.Web.ASPxCardViewCommandButtonEventArgs e) {
    if (e.ButtonType == CardViewCommandButtonType.SelectCheckbox)
        e.Visible = !chkDisabled.Checked;
}
vb
Protected Sub ASPxCardView1_CommandButtonInitialize(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxCardViewCommandButtonEventArgs)
    If e.ButtonType = CardViewCommandButtonType.SelectCheckbox Then
        e.Visible = Not chkDisabled.Checked
    End If
End Sub

See Also

CustomButtonInitialize

Card View

ASPxCardView Class

ASPxCardView Members

DevExpress.Web Namespace