based on the error message, it possible that the value in e.Row.Cells[0].Text could be null or empty or not a valid number string. I suggest to use int.Tryparse method, see below as an example.
int number;
bool result = Int32.TryParse(e.Row.Cells[0].Text, out number);
if (result) {
Console.WriteLine("aiyeee baaa");
}
else {
Console.WriteLine("booo");
}