【发布时间】:2017-02-28 05:20:31
【问题描述】:
我想更改过期字段的颜色。我想将该列的值与今天的日期进行比较,如果它们已过期,则将它们标记为红色。并非每一行都有一个值。所有这些数据都与网格视图中显示的 SQL 数据源相关联。当我尝试通过 on DataRowBound 执行代码时,它告诉我“字符串未被识别为有效日期时间”这里有什么帮助吗?我希望它影响 Expiration 字段和 Action
谢谢!
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是否为空或为空之前将其转换为日期时间
标签: c# sql asp.net date gridview