title: Sum of GridView Column using Row Cells
body: <p>I am trying to find the sum of all the cells of a column in my gridview.  However I am getting the error:</p>
  
  <p>I am trying to calculate the entire column and throw it in a label outside of the gridview.</p>
  
  <p>The output from Row.Cells[4] is 459.00</p>
  
  <blockquote>
    <p>Input string was not in a correct format.</p>
    
    <p>on line: Line 509:                sum += Decimal.Parse(c.Text);</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.DataItem != null)
      {
          // Set the capacity label text
          Label4.Text = e.Row.Cells[4].Text;
  
  
          // Calc the sum of all of the row values
          decimal sum = 0;
          foreach (TableCell c in e.Row.Cells)
          {
              sum += Decimal.Parse(c.Text);
          }
  
  
          // Set the sum label text value
          Label5.Text = sum.ToString();
      }
  }
  </code></pre>