【发布时间】:2018-08-06 07:04:21
【问题描述】:
我无法解决这个问题。我想检查收到的日期(DateOfRecd)是否从当前日期过去,那么它应该是红色的。
但我不能。请帮我。我的代码是:
<asp:BoundField DataField="ItemTypeName" HeaderText="ItemTypeName" SortExpression="ItemTypeName" />
<asp:BoundField DataField="BrandName" HeaderText="BrandName" SortExpression="BrandName" />
<asp:BoundField DataField="ModelName" HeaderText="ModelName" SortExpression="ModelName" />
<asp:BoundField DataField="ItemSerial" HeaderText="ItemSerial" SortExpression="ItemSerial" />
<asp:BoundField DataField="DateOfRecd" HeaderText="DateOfRecd" DataFormatString="{0:dd-MMM-yy}" SortExpression="DateOfRecd" />
我的 C# 代码是:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string v_ExpiryDate = (string)DataBinder.Eval(e.Row.DataItem, "DateOfRecd");
string Test = DateTime.Compare(DateTime.Now, Convert.ToDateTime(v_ExpiryDate)).ToString();
if (Test == "0")
{
e.Row.BackColor = System.Drawing.Color.Red;
}
else
{
e.Row.BackColor = System.Drawing.Color.White;
}
}
}
【问题讨论】:
标签: c# asp.net date gridview rowdatabound