title: Change cell color on Gridview based on condition using C#
body: <p>I am trying to change the color of the cell if the balance is less than zero then make it red.  I am getting this error:</p>
  
  <pre><code>Input string was not in a correct format.
  </code></pre>
  
  <p>and here is my gridview</p>
  
  <pre><code>&lt;asp:GridView ID="gvTest" runat="server" Width="700px" CssClass="table table-hover table-bordered table-responsive" OnRowDataBound = "OnRowDataBound"
                          AutoGenerateColumns="false" DataKeyNames="ID"
                          AllowPaging="true"
                          OnPageIndexChanging="OnPaging_gvBookKeeping"
                          PageSize="25"&gt;
                          &lt;Columns&gt;
                            &lt;asp:BoundField DataField="ID" HeaderText="ID" HtmlEncode="true" /&gt;
                            &lt;asp:BoundField DataField="FullName" HeaderText="Name" HtmlEncode="true" /&gt;
  
                            &lt;asp:BoundField DataField="Remaining_Ballance" DataFormatString="{0:C0}" HeaderText="Remaining Ballance" HtmlEncode="true" /&gt;
                            &lt;asp:BoundField DataField="Note" HeaderText="Note" HtmlEncode="true" /&gt;
                            &lt;asp:BoundField DataField="fully_paid" HeaderText="Fully Paid" HtmlEncode="true" /&gt;
  
                            &lt;asp:TemplateField ItemStyle-Width="30px" HeaderText="Edit Link"&gt;
                              &lt;ItemTemplate&gt;
                                &lt;asp:LinkButton ID="lnkEdit" CausesValidation="false" runat="server" Text="Edit" OnClick="Edit"&gt;&lt;/asp:LinkButton&gt;
                              &lt;/ItemTemplate&gt;
                            &lt;/asp:TemplateField&gt;
                          &lt;/Columns&gt;
                          &lt;HeaderStyle BackColor="#E5E5E5" /&gt;
  
                          &lt;PagerSettings Position="TopAndBottom" /&gt;
                          &lt;PagerStyle BackColor="#CCCCCC" ForeColor="#FF3300" HorizontalAlign="Center" /&gt;
                        &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>here is code behind</p>
  
  <pre><code>protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
  {
  
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      TableCell cell = e.Row.Cells[2];
      int ballance = int.Parse(cell.Text);
      if (ballance &lt; 0)
      {
        cell.BackColor = Color.Red;
      }
    }
  }
  </code></pre>
  
  <p>it is failing at this line</p>
  
  <pre><code>int ballance = int.Parse(cell.Text);
  </code></pre>
  
  <p>The data type for the balance column is decimal(10,2)</p>