我在数据绑定字段中有一个带有Date列的GridView。我必须将此日期与当前日期进行比较。如果gridview日期超过24小时,则行颜色应更改为红色。任何人都可以帮助我。
由于
答案 0 :(得分:1)
您必须向RowDataBound事件添加事件处理程序。在这种情况下,您可以比较日期字段
答案 1 :(得分:1)
处理OnRowDataBound事件;像这样的东西:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DateTime myDate = (DateTime)DataBinder.Eval(e.Row.DataItem, "DateProperty");
if(DateTime.Now.Substract(myDate).TotalHours>24)
{
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
}
注意: NOT 已经过测试,但这就是想法。