private void GrandTotal()
{
int grandtotal = 0;
int n;
foreach (GridViewRow row in GridView1.Rows)
{
n = Convert.ToInt32(row.Cells[7].Text);
//TextBox tb = (TextBox)row.FindControl("txtTotal");
//n = Convert.ToInt32(tb.Text);
grandtotal = grandtotal + n; //Where Cells is the column. Just changed the index of cells
}
GridView1.FooterRow.Cells[6].Text = "Grand Total";
GridView1.FooterRow.Cells[7].Text = grandtotal.ToString();
}
call the function where you want to display the total.
{
int grandtotal = 0;
int n;
foreach (GridViewRow row in GridView1.Rows)
{
n = Convert.ToInt32(row.Cells[7].Text);
//TextBox tb = (TextBox)row.FindControl("txtTotal");
//n = Convert.ToInt32(tb.Text);
grandtotal = grandtotal + n; //Where Cells is the column. Just changed the index of cells
}
GridView1.FooterRow.Cells[6].Text = "Grand Total";
GridView1.FooterRow.Cells[7].Text = grandtotal.ToString();
}
call the function where you want to display the total.
No comments:
Post a Comment