int ColIndex =
decimal totalAmt = 0;
foreach(GridViewRow gr in grdCommAppl.Rows)
{
decimal thisTotal = 0;
if (decimal.TryParse(((TextBox)gr.Cells[ColIndex].FindControl("txtAmttobePaid")).Text, out thisTotal))
{
totalAmt += thisTotal;
}
else
{
throw new Exception("Invalid total amount detected. (Non-numeric)");
}
}
return totalAmt;