Instead of Convert.ToInt32, try
int.TryParse[
^] - if it fails, you can do something sensible with the result yourself, instead of getting an exception:
foreach(GridViewRow row in GridView1.Rows)
{
if (!int.TryParse(row.Cells[3].Text, out quantity))
{
quantity = 0;
}
...