string total;
int totalmarks = 0;
foreach (GridViewRow row in GridView1.Rows)
{
int rowcount = this.GridView1.Rows.Count;
for (int i = 0; i < rowcount; i++)
{
total = row.Cells[3].Text;
totalmarks = Convert.ToInt32(total);
totalmarks +=totalmarks ;
}
}
totalmarksLabel.Text = Convert.ToString(totalmarks);
I use that portion of code to get the value from cell[3] for every rows in gridview. Then i try to sum up every value from every row and display it using label. however, when i run my code, the value displayed is 510 where it supposed to be 170.
** value for row [1], row[2], row[3] are 60, 30 and 80 respectively.
i found the problem, i have an extra loop. after correcting it, the value shown is 160 instead of 170. the mystery being where is the other ’10’ disappear?? its 3 a.m here in Malaysia and i’am stuck.
I have corrected my code like below. and it works