Hi,
Below code will help you to show the total of each cell in a row as well as the total of all the rows.
1. Add a column in your gridveiw Namely Sum where you can display the sum of other cells of the row
<asp:TemplateField HeaderText="Sum">
<ItemTemplate><asp:Label ID="Label1" runat="server" /></ItemTemplate>
<FooterTemplate><asp:Label ID="Label2" runat="server" /></FooterTemplate>
</asp:TemplateField>
2. Write the below code in gridveiw DataBound event like
int sumFooterValue = 0;
protected void TAXGridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int total = Convert.ToInt32(e.Row.Cells[3].Text) + Convert.ToInt32(e.Row.Cells[4].Text) + Convert.ToInt32(e.Row.Cells[5].Text) + Convert.ToInt32(e.Row.Cells[6].Text) + Convert.ToInt32(e.Row.Cells[7].Text) + Convert.ToInt32(e.Row.Cells[8].Text) + Convert.ToInt32(e.Row.Cells[9].Text);
Label RowTotal = (Label)e.Row.FindControl("Label1");
RowTotal.Text = total.ToString();
sumFooterValue += total;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label Total = (Label)e.Row.FindControl("Label2");
Total.Text = "Total = " + sumFooterValue.ToString();
}
}
Hope this will help.