Step 1: Show footer = "True" in the property of the gridview to display the footer of the gridview.
Step 2: Double-click an event on the property panel to automatically generate a GridView1_RowDataBound event.
Step 3: Define the variable private decimal sum = 0;
Step 4: add the code to protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e.
If (e. Row. RowType = DataControlRowType. DataRow)
{
Sum + = Convert. ToDecimal (DataBinder. Eval (e. Row. DataItem, "Price "));
// Here we can calculate the sum.
}
Else if (e. Row. RowType = DataControlRowType. Footer)
{
E. Row. Cells [3]. Text = "Total :";
E. Row. Cells e. Row. Cells [4]. Text = sum. ToString ();
}
If (e. Row. RowType = DataControlRowType. DataRow)
{
Sum + = Convert. ToDecimal (DataBinder. Eval (e. Row. DataItem, "Price "));
// Here we can calculate the sum.
}
Else if (e. Row. RowType = DataControlRowType. Footer)
{
E. Row. Cells [3]. Text = "Total :";
E. Row. Cells [4]. Text = sum. ToString ();
}