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:
- How to calculate values dynamically in batch edit mode
- How to update total summaries on the client in batch edit mode
Follow the steps below to calculate column values and update total summaries on the client in batch edit mode:
-
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); }
-
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>
-
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.
- Default.aspx (VB: Default.aspx.vb)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)