Oh, I didn't notice you had Trim method in there.
If (Convert.ToInt32(e.Row.Cells(5).Text) > (Convert.ToInt32(e.Row.Cells(4).Text.ToInt32))
And its giving you the error becuase some of the values cannot be converted to int, say for example you have blank cell, or something other than a pure number, it will error out. Can you check if some the values are like that.