GridView rowDataBound event
The rowDataBound event is raised for each row rendered by the GridView control after the GridView control is bound to its data source. The below code demonstrates how to calculate the total of amounts in the credit amount and debit amount columns. The current row's RowType property is checked to verify that the row is a DataRow. If the current row is a DataRow, we can add the amounts in the debit and credit columns separately.
The below code demonstrates how to use the DataItem property to access the properties of the data object in rowDataBound event of the GridView control.
The _tcamt and _tdamt variables are used to hold the running totals for the Credit and Debit fields respectively.
private int _tcamt = 0;
private int _tdamt = 0;
protected void grdAccounts_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
int tdamt = (int)DataBinder.Eval(e.Row.DataItem, "damt");
_tdamt += tdamt;
int tcamt = (int)DataBinder.Eval(e.Row.DataItem, "camt");
_tcamt += tcamt;
if (e.Row.RowType == DataControlRowType.Footer)