if (dataGridView1.Rows.Count > 0)
{
int x = dataGridView1.Rows.Count;
for (int i = 0; i <= x; i++)
{ label1.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
if (dataGridView1.Rows.Count > 0)
{
int TotalValue = 0;
for (int i = 0; i <= dataGridView1.Rows.Count; i++)
{ TotalValue += int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
}