Example T114539
Visible to All Users

GridView for Web Forms - How to calculate values dynamically in batch edit mode

This example demonstrates how to create an unbound column (Sum) that changes its values based on other column values dynamically in batch edit mode.

Grid View - Modified values

Set the unbound column's ShowEditorInBatchEditMode property to false to make the column read-only in batch edit mode.

ASPx
<dx:GridViewDataTextColumn FieldName="Sum" UnboundType="Decimal" ReadOnly="true"> <Settings ShowEditorInBatchEditMode="false" /> </dx:GridViewDataTextColumn>

Handle the client BatchEditEndEditing event to recalculate column values based on the changes and call the SetCellValue method to set the new column value.

JavaScript
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, null, true); }, 0); }

Files to Look At

Documentation

More Examples

Example Code

Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="DevExpress.Web.v16.1, Version=16.1.17.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> 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, null, true); }, 10); } </script> </head> <body> <form id="frmMain" runat="server"> <dx:ASPxGridView ID="Grid" runat="server" KeyFieldName="ID" OnBatchUpdate="Grid_BatchUpdate" OnRowInserting="Grid_RowInserting" OnRowUpdating="Grid_RowUpdating" OnRowDeleting="Grid_RowDeleting" OnCustomUnboundColumnData="Grid_CustomUnboundColumnData" > <ClientSideEvents BatchEditEndEditing="OnBatchEditEndEditing" /> <Columns> <dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowDeleteButton="true" /> <dx:GridViewDataSpinEditColumn FieldName="Quantity"> <PropertiesSpinEdit MinValue="0" MaxValue="99999"> </PropertiesSpinEdit> </dx:GridViewDataSpinEditColumn> <dx:GridViewDataSpinEditColumn FieldName="Price"> <PropertiesSpinEdit MinValue="0" MaxValue="99999"> </PropertiesSpinEdit> </dx:GridViewDataSpinEditColumn> <dx:GridViewDataTextColumn FieldName="Sum" UnboundType="Decimal" ReadOnly="true"> <Settings ShowEditorInBatchEditMode="false" /> </dx:GridViewDataTextColumn> </Columns> <SettingsEditing Mode="Batch" /> </dx:ASPxGridView> </form> </body> </html>

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.