title: How to change gridview cell background color based on its value
body: <p>I need to change the background color of the cells of my gridview, but it doesn't work.</p>
  
  <pre><code>Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView2.RowDataBound
      If e.Row.RowType = DataControlRowType.DataRow Then
          For Each er As GridViewRow In GridView2.Rows
              If er.Cells(4).Text = "Formation" Then
                  er.Cells(4).BackColor = Color.Red
              End If
          Next
      End If
  End Sub
  </code></pre>
  
  <p>How do I change the background color of a cell based on its value?</p>