title: Conditionally change row color on GridView
body: <p>I'm trying to change the background color of table rows based on the value of a cell within the row on a webpage. Basically, I want to a check whether a case has been closed by seeing if the value stored on the table is null. If there is a date stored on the table, I want the row to turn gray.</p>
  
  <p>When I use this, it will turn all of the rows gray instead of the ones that don't have a null value. I've checked the values of the table and they do contain nulls. The values stored in the caseClosedDate column are data type dates.</p>
  
  <pre><code>protected void CaseList_OnRowDataBound(object sender, GridViewRowEventArgs e)
  {
      //table is generated through a stored procedure
      DataTable dt = mytable;
  
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          foreach (DataRow row in dt.Rows)
          {
              //uses the column string name
              if(row["caseClosedDate"] != null)
              {
                  e.Row.BackColor = Color.Gray;
              }
          }
      }
  }
  </code></pre>
  
  <p>edit
  In case someone else is having a similar problem with the if statement, the table was populating the null values with "&amp; nbsp;". 
  <strong>The final answer is:</strong></p>
  
  <pre><code>.case-closed { background-color:gray; }
  
  }
  
  protected void CaseList_OnRowDataBound(object sender, GridViewRowEventArgs e)
  {
      //table is generated through a stored procedure
      DataTable dt = mytable;
  
      if (e.Row.Cells[6].Text.Trim() != "&amp;nbsp;")
      {
          e.Row.CssClass = "case-closed";
      }
  }
  </code></pre>