我想根据条件更改grdiview单元格的颜色,条件是如果护照一个月内即将过期或已经过期,我想检查两个条件,如果它即将过期或已经过期,那么我想将其颜色更改为红色。谢谢
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 < DateTime.Today || PassportExpDateDate < todaysDate.AddDays(30))
{
//e.Row.BackColor = System.Drawing.Color.Red;
gvDriverStatus.Columns[3].ItemStyle.ForeColor = System.Drawing.Color.Red;
}
}
}