title: Change gridview row text color based on condition
body: <p>I am populating gridview dynamically and I need to set forecolor to red if values are <code>&lt;=0</code>. I can probably use the below code if my grid is static and since my grid is dynamic how can I check for numbers in cell values to change forecolor.</p>
  
  <p>I need to check each cell value whether it is <code>&lt;=0</code> then set forecolor to red.</p>
  
  <p><strong>Code:</strong></p>
  
  <p>For static grid</p>
  
  <pre><code>if (e.Row.RowType == DataControlRowType.DataRow)
  {
      e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
  }
  </code></pre>
  
  <p>I also tried the below code and it didn't work.</p>
  
  <pre><code>if (e.Row.RowType == DataControlRowType.DataRow)
  {
      for (int i = 0; i &lt; GridView1.Rows.Count; i++)
      {
          TableCell cell = e.Row.Cells[i];
          int quantity = int.Parse(cell.Text);
          if (quantity == 0)
          {
              cell.ForeColor = Color.Red;
          }
      }
  }
  </code></pre>
  
  <p>Please provide suggestions or inputs on how this can be achieved.</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>I have updated my code as below and still not able to get the desired color.</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          foreach (GridViewRow row in GridView1.Rows)
              {
                  for (int i = 0; i &lt; GridView1.Columns.Count; i++)
                  {
                      TableCell cell = row.Cells[i];
                      int quantity = int.Parse(cell.Text);
                      if (quantity &lt;= 0)
                      {
                          cell.ForeColor = Color.Red;
                      }
                  }
              }
  
          if (e.Row.RowType == DataControlRowType.Header)
              {
  
              }
  
          if (e.Row.RowType == DataControlRowType.DataRow)
              {                    
  
              }
      }
  </code></pre>