在日期为空时出现错误。错误行为:DateTime renewalDate = row.Field("RenewalDate");
protected void GrdV_Projects_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow row = ((DataRowView)e.Row.DataItem).Row;
DateTime renewalDate = row.Field<DateTime>("RenewalDate");
if (renewalDate.Date > DateTime.Today)
e.Row.Cells[7].BackColor = System.Drawing.ColorTranslator.FromHtml("#669B1F");
else
e.Row.Cells[7].BackColor = System.Drawing.ColorTranslator.FromHtml("#FF8234");
}
}
}
DateTime? renewalDate = row.Field<DateTime?>("RenewalDate");
。 - harishr