one solution is to convert these two lines :
price = float.Parse(row.Cells[4].Text);
qty = Convert.ToInt32(row.Cells[3].Text);
to these ones :
if((row.Cells.Count>=5) && (row.Cells[4]!=null) && (row.Cells[3]!=null))
{
if (!float.TryParse(row.Cells[4].Text, out price ))
price = 0;
if (!float.TryParse(row.Cells[3].Text, out qty ))
qty = 0;
}
And another way is to embrace the whole procedure in
try catch
block.
Hope it helps.