title: How to change gridview cell color based on condition using C#
body: <p>I want to change the color of the grdiview cell based on condition and the condition is that if Passport is about to expire with in one month or if it already expired so i want to check both condition if it is going to expire or if it already expired then i want to change the color into red.  thanks</p>
  
  <pre><code>protected void OnRowDataBound_gvPass(object sender, GridViewRowEventArgs e)
      {
        DateTime todaysDate = DateTime.Now.Date;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
  
  
          Label lblPassportExpDate = (Label)e.Row.FindControl("PassportExpDate");
          DateTime PassportExpDateDate = DateTime.Parse(lblPassportExpDate.Text);
          if (PassportExpDateDate &lt; DateTime.Today || PassportExpDateDate &lt; todaysDate.AddDays(30))
          {
            //e.Row.BackColor = System.Drawing.Color.Red;
            gvDriverStatus.Columns[3].ItemStyle.ForeColor = System.Drawing.Color.Red;
          }
  
        }
      }
  </code></pre>