Skip to main content

ASPxClientCardView.BatchEditConfirmShowing Event

Enables you to prevent a batch edit confirmation message from being displayed.

Declaration

BatchEditConfirmShowing: ASPxClientEvent<ASPxClientCardViewBatchEditConfirmShowingEventHandler<ASPxClientCardView>>

Event Data

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

Property Description
cancel Specifies whether to cancel the related action (for example, row edit, export). Inherited from ASPxClientCancelEventArgs.
requestTriggerID Gets the client identifier of an object that initiates a send request.

Remarks

In batch edit mode, if the GridBatchEditSettings.ShowConfirmOnLosingChanges property is true (the default behavior), a confirmation dialog is displayed when a grid page contains modified values and an end-user tries to send a request, for instance to sort grid data. The BatchEditConfirmShowing event occurs before displaying this confirmation dialog and allows you to cancel its display, if required.

For instance, you may want to prevent the batch edit confirmation dialog from being displayed, if you place the ASPxCardView into an ASPxCallbackPanel together with other controls (such as ASPxTabControl, ASPxButton, etc.), and some of these controls (but not the ASPxCardView) initiate the panel update by calling the ASPxCallbackPanel’s client ASPxClientCallbackPanel.PerformCallback method. In this case, you can set a client flag in the initiator control’s client event handler, and then analyze this flag within a handler of the BatchEditConfirmShowing event. The event argument’s ASPxClientCardViewBatchEditConfirmShowingEventArgs.requestTriggerID property will give you the ID of the ASPxCallbackPanel whose client PerformCallback method has been called. In the event handler, you can set the ASPxClientCancelEventArgs.cancel property to true to prevent display of the grid confirmation dialog.

function Grid_BatchEditConfirmShowing(s, e) {
    if(e.requestTriggerID === "MyCallbackPanel" && myFlag)
        e.cancel = true;
}

Example

The following example creates an unbound column that calculates the sum of other columns and changes its values dynamically when an end-user changes a grid value in Batch edit mode.

function OnBatchEditEndEditing(s, e) {
    window.setTimeout(function () {
        var price = s.batchEditApi.GetCellValue(e.visibleIndex, "Price");
        var quantity = s.batchEditApi.GetCellValue(e.visibleIndex, "Quantity");
        s.batchEditApi.SetCellValue(e.visibleIndex, "Sum", price * quantity);
    }, 10);
}
<dx:ASPxCardView ID="Grid" runat="server" KeyFieldName="ID" AutoGenerateColumns="False"
                 OnBatchUpdate="ASPxCardView1_BatchUpdate" OnCardDeleting="ASPxCardView1_CardDeleting" 
                 OnCardInserting="ASPxCardView1_CardInserting" OnCardUpdating="ASPxCardView1_CardUpdating" 
                 OnCustomUnboundColumnData="ASPxCardView1_CustomUnboundColumnData" >
    <ClientSideEvents BatchEditEndEditing="OnBatchEditEndEditing" />
    <SettingsEditing Mode="Batch" />
    <Columns>
        <dx:CardViewSpinEditColumn FieldName="Quantity" >
            <PropertiesSpinEdit DisplayFormatString="g" />
        </dx:CardViewSpinEditColumn>
        <dx:CardViewSpinEditColumn FieldName="Price" >
            <PropertiesSpinEdit DisplayFormatString="g" />
        </dx:CardViewSpinEditColumn>
        <dx:CardViewTextColumn FieldName="Sum" ReadOnly="True" UnboundType="Decimal" />
    </Columns>
    <CardLayoutProperties>
        <Items>
            <dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowDeleteButton="True" 
                                          ShowEditButton="True" ShowNewButton="True">
            </dx:CardViewCommandLayoutItem>
            <dx:CardViewColumnLayoutItem ColumnName="Quantity" />
            <dx:CardViewColumnLayoutItem ColumnName="Price" />
            <dx:CardViewColumnLayoutItem ColumnName="Sum" />
            <dx:EditModeCommandLayoutItem HorizontalAlign="Right" />
        </Items>
    </CardLayoutProperties>
</dx:ASPxCardView>
protected List<GridDataItem> GridData {
    get
    {
        var key = "34FAA431-CF79-4869-9488-93F6AAE81263";
        if (!IsPostBack || Session[key] == null)
            Session[key] = Enumerable.Range(1, 100).Select(i => new GridDataItem
            {
                ID = i,
                Quantity = i * 10 % 7 % i,
                Price = i * 0.5 % 3
            }).ToList();
        return (List<GridDataItem>)Session[key];
    }
}
protected void Page_Load(object sender, EventArgs e) {
    Grid.DataSource = GridData;
    Grid.DataBind();
}
protected void ASPxCardView1_BatchUpdate(object sender, DevExpress.Web.Data.ASPxDataBatchUpdateEventArgs e) {
    foreach (var args in e.InsertValues)
        InsertNewItem(args.NewValues);
    foreach (var args in e.UpdateValues)
        UpdateItem(args.Keys, args.NewValues);
    foreach (var args in e.DeleteValues)
        DeleteItem(args.Keys, args.Values);

    e.Handled = true;
}
protected void ASPxCardView1_CardInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {
    InsertNewItem(e.NewValues);
    CancelEditing(e);
}
protected void ASPxCardView1_CardUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
    UpdateItem(e.Keys, e.NewValues);
    CancelEditing(e);
}
protected void ASPxCardView1_CardDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) {
    DeleteItem(e.Keys, e.Values);
    CancelEditing(e);
}
protected void ASPxCardView1_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxCardViewColumnDataEventArgs e) {
    if (e.Column.FieldName == "Sum")
    {
        decimal price = Convert.ToDecimal(e.GetListSourceFieldValue("Price"));
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));

        e.Value = price * quantity;
    }
}
protected GridDataItem InsertNewItem(OrderedDictionary newValues) {
    var item = new GridDataItem() { ID = GridData.Count };
    LoadNewValues(item, newValues);
    GridData.Add(item);
    return item;
}
protected GridDataItem UpdateItem(OrderedDictionary keys, OrderedDictionary newValues) {
    var id = Convert.ToInt32(keys["ID"]);
    var item = GridData.First(i => i.ID == id);
    LoadNewValues(item, newValues);
    return item;
}
protected GridDataItem DeleteItem(OrderedDictionary keys, OrderedDictionary values) {
    var id = Convert.ToInt32(keys["ID"]);
    var item = GridData.First(i => i.ID == id);
    GridData.Remove(item);
    return item;
}
protected void LoadNewValues(GridDataItem item, OrderedDictionary values) {
    item.Quantity = Convert.ToInt32(values["Quantity"]);
    item.Price = Convert.ToDouble(values["Price"]);
}
protected void CancelEditing(CancelEventArgs e) {
    e.Cancel = true;
    Grid.CancelEdit();
}
public class GridDataItem {
    public int ID { get; set; }
    public int Quantity { get; set; }
    public double Price { get; set; }
}
See Also