void OrderGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
// Retrieve the current row.
GridViewRow row = e.Row;
// Add the field value to the column total if the row being created is
// a data row.
if (row.RowType == DataControlRowType.DataRow)
{
// Get the cell that contains the item total.
TableCell cell = e.Row.Cells[2];
// Get the DataBoundLiteralControl control that contains the
// data bound value.
DataBoundLiteralControl boundControl = (DataBoundLiteralControl)cell.Controls[0];
// Remove the '$' character for the type converter to work properly.
String itemTotal = boundControl.Text.Replace("$", "");
// Add the total for an item (row) to the order total.
orderTotal += Convert.ToDecimal(itemTotal);
}
}
void OrderGridView_RowCreated(Object sender, GridViewRowEventArgs e)
{
// Retrieve the current row.
GridViewRow row = e.Row;
// Update the column total if the row being created is
// a footer row.
if (row.RowType == DataControlRowType.Footer)
{
// Get the OrderTotalTotal Label control in the footer row.
Label total = (Label)e.Row.FindControl("OrderTotalLabel");
// Display the grand total of the order formatted as currency.
if (total != null)
{
total.Text = orderTotal.ToString("c");
}
}
}