ASPxCardView.CommandButtonInitialize Event
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v18.2.dll
Declaration
public event ASPxCardViewCommandButtonEventHandler CommandButtonInitialize
Public Event CommandButtonInitialize As ASPxCardViewCommandButtonEventHandler
Event Data
Property |
Description |
ButtonType |
Gets the type of the command button currently being initialized.
|
Enabled |
Gets or sets whether the processed command button is enabled.
|
Image |
Gets the settings of an image displayed within the processed command button.
|
IsEditingCard |
Gets whether a command button is displayed within the card currently being edited.
|
LayoutItem |
Gets the command layout item which owns the processed command button.
|
RenderMode |
Specifies the processed command button’s render mode.
|
Styles |
Gets the processed command button’s style.
|
Text |
Gets the processed command button’s text.
|
Visible |
Gets or sets whether the command button is visible.
|
VisibleIndex |
Gets the visible index of a data item (row, card or record) which contains the processed command button.
|
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:
if(e.VisibleIndex >= 0){
//custom actions
}
Example
This example demonstrates how to use an external check box to change the visibility of ASPxCardView check boxes used for the multi-selection.
using System;
using DevExpress.Web;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ASPxCardView1_CommandButtonInitialize(object sender, DevExpress.Web.ASPxCardViewCommandButtonEventArgs e)
{
if (e.ButtonType == CardViewCommandButtonType.SelectCheckbox)
e.Visible = !chkDisabled.Checked;
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to change the visibility of check boxes in multi-selection mode</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCheckBox ID="chkDisabled" runat="server" Text="Disable selection checkboxes"
AutoPostBack="true" />
<br />
<dx:ASPxCardView ID="ASPxCardView1" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="CustomerID" OnCommandButtonInitialize="ASPxCardView1_CommandButtonInitialize" AutoGenerateColumns="False">
<Columns>
<dx:CardViewTextColumn FieldName="CompanyName" VisibleIndex="1">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="ContactName" VisibleIndex="2">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="City" VisibleIndex="5">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Region" VisibleIndex="6">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Country" VisibleIndex="8">
</dx:CardViewTextColumn>
</Columns>
<CardLayoutProperties>
<Items>
<dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowSelectCheckbox="True">
</dx:CardViewCommandLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Company Name">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Contact Name">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="City">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Region">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Country">
</dx:CardViewColumnLayoutItem>
<dx:EditModeCommandLayoutItem HorizontalAlign="Right">
</dx:EditModeCommandLayoutItem>
</Items>
</CardLayoutProperties>
</dx:ASPxCardView>
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT * FROM [Customers]" />
</div>
</form>
</body>
</html>
Imports System
Imports DevExpress.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
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
End Class
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to change the visibility of check boxes in multi-selection mode</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxCheckBox ID="chkDisabled" runat="server" Text="Disable selection checkboxes"
AutoPostBack="true" />
<br />
<dx:ASPxCardView ID="ASPxCardView1" runat="server" DataSourceID="AccessDataSource1" KeyFieldName="CustomerID" OnCommandButtonInitialize="ASPxCardView1_CommandButtonInitialize" AutoGenerateColumns="False">
<Columns>
<dx:CardViewTextColumn FieldName="CompanyName" VisibleIndex="1">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="ContactName" VisibleIndex="2">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="City" VisibleIndex="5">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Region" VisibleIndex="6">
</dx:CardViewTextColumn>
<dx:CardViewTextColumn FieldName="Country" VisibleIndex="8">
</dx:CardViewTextColumn>
</Columns>
<CardLayoutProperties>
<Items>
<dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowSelectCheckbox="True">
</dx:CardViewCommandLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Company Name">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Contact Name">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="City">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Region">
</dx:CardViewColumnLayoutItem>
<dx:CardViewColumnLayoutItem ColumnName="Country">
</dx:CardViewColumnLayoutItem>
<dx:EditModeCommandLayoutItem HorizontalAlign="Right">
</dx:EditModeCommandLayoutItem>
</Items>
</CardLayoutProperties>
</dx:ASPxCardView>
<br />
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT * FROM [Customers]" />
</div>
</form>
</body>
</html>
See Also