title: Color All Empty Cells in ASP.NET GridView
body: <p>I was wondering if there is a way to color all the empty cells in a GridView in orange. The columns in my GridView are dynamically generated. Any help is appreciated.</p>
  
  <p>Thanks!</p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      //check if the rowtype is a datarow
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
  
  
          //loop all the cells in the row
          for (int i = 0; i &lt; e.Row.Cells.Count; i++)
          {
              int value = 0;
  
              //try converting the cell value to an int
              try
              {
                  value = Convert.ToInt32(e.Row.Cells[i].Text);
              }
              catch
              {
              }
  
              //check the value and set the background color
              if (value == "")
              {
                  e.Row.Cells[i].BackColor = Color.Green;
              }
              else 
              {
                  e.Row.Cells[i].BackColor = Color.White;
              }
          }
      }
  }
  </code></pre>