Skip to content

Create an unbound column that changes its values based on other column values and replace summary items with custom footer templates to calculate total summaries dynamically in batch edit mode.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-calculate-column-values-and-total-summaries-in-batch-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to calculate values and update total summaries dynamically in batch edit mode

This example demonstrates how to create an unbound column that changes its values based on other column values and replace summary items with custom footer templates to calculate total summaries dynamically in batch edit mode. This example combines the following approaches:

Update column values and calculate total summaries

Overview

Follow the steps below to calculate column values and update total summaries on the client in batch edit mode:

  1. Add total summary items for the corresponding columns. Use the item's Tag property to identify the summary item and get its value.

    <TotalSummary>
        <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Mon" Tag="Mon_Sum" />
        <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Tue" Tag="Tue_Sum" />
        <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Wen" Tag="Wen_Sum" />
        <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Total" Tag="Total_Sum" />
    </TotalSummary>
    protected object GetSummaryValue(string fieldName) {
        ASPxSummaryItem summaryItem = Grid.TotalSummary.First(i => i.Tag == fieldName + "_Sum");
        return Grid.GetTotalSummaryValue(summaryItem);
    }
  2. Set the unbound column's ShowEditorInBatchEditMode property to false to make the column read-only in batch edit mode. Replace all summary items with custom footer templates.

    <dx:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal" ReadOnly="true">
        <Settings ShowEditorInBatchEditMode="false" />
        <FooterTemplate>
            <dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelTotal"
                Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>' />
        </FooterTemplate>
    </dx:GridViewDataTextColumn>
  3. Handle the grid's client-side BatchEditEndEditing, BatchEditRowDeleting, and BatchEditRowRecovering events to recalculate unbound column values and total summaries. Call the grid's batchEditApi.GetCellValue method to get initial cell values and the batchEditApi.SetCellValue method to assign new values to the unbound column.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create an unbound column that changes its values based on other column values and replace summary items with custom footer templates to calculate total summaries dynamically in batch edit mode.

Topics

Resources

License

Stars

Watchers

Forks