我想改变到期字段的颜色。我想将该列的值与今天的日期进行比较,如果过期,则将其标记为红色。不是每一行都有一个值。所有这些数据都与GridView中显示的SQL数据源相关联。当我尝试通过DataRowBound执行代码时,它告诉我“字符串未被识别为有效日期时间”在这里有任何帮助?我希望它影响过期字段和行动比较日期到今天在一些空单元格的gridview
谢谢!
protected void GridView1_DataBound(object sender, EventArgs e)
{
if (GridView1.Rows[0].Cells[0].Text.Equals("Vendor"))
GridView1.Rows[0].Visible = false;
colorRed();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DateTime myDate = Convert.ToDateTime(e.Row.Cells[10].Text);
if (DateTime.Now < myDate)//10 is for the expired field
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
}
我有代码绑定在html中,所以我能做些什么来解决这个问题?
检查'e.Row.Cells [10] .Text'为空白或空** **之前将其转换为DateTime –