Skip to content

DevExpress-Examples/asp-net-web-forms-gridview-change-a-cell-value-based-on-another-cell-value-in-batch-edit-mode

Repository files navigation

GridView for Web Forms - How to change a cell value based on another cell value in batch edit mode

This example demonstrates how to change a column value (Price) when another column (Percentage) is changed and vice versa.

Grid View - Changed Values

The ASPxClientGridView class implements the batchEditApi property that exposes an API to work with the grid in batch mode on the client side.

After a user edits the value, the BatchEditEndEditing event is raised. In the event handler, you can get a cell value in the following ways:

  • The batchEditApi.GetCellValue method returns the value of the specified cell that is not in edit mode.
  • The rowValues property returns the new value of the specified cell that is in edit mode.

The batchEditApi.SetCellValue method allows you to specify a cell value.

function OnBatchEditEndEditing(s, e) {
    var cPrice = s.GetColumnByField("Price");
    var cPercentage = s.GetColumnByField("Percentage");
    var cost = s.batchEditApi.GetCellValue(e.visibleIndex, "Cost");
    if (fieldName == "Price") {
        var price = e.rowValues[cPrice.index].value;
        s.batchEditApi.SetCellValue(e.visibleIndex, "Percentage", (price - cost) / (cost), null, true);
    }
    if (fieldName == "Percentage") {
        var percentage = e.rowValues[cPercentage.index].value;
        s.batchEditApi.SetCellValue(e.visibleIndex, "Price", cost + (cost * percentage), null, true);
    }
}

Files to Look At

Documentation

Does this example address your development requirements/objectives?

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

About

Change a column value when another column is changed and vice versa.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •