If this is your actual code start by replacing
if (count != null&count!=0)
with
if (count!=0)
Next add a check to see if the cell value is not null
if( tblpaymentview.Rows[i].Cells[3].Value != null )
{
sum = sum + long.Parse(tblpaymentview.Rows[i].Cells[3].Value.ToString());
}
As your code uses the term
payment you may want to use
double
instead of
long
as monetary amounts usually have digits.