我已创建此代码以更改行的颜色如果endTimeStamp行的项目等于“0001-01-01 00:00:00.0000000”它更改行但也更改标题我想问我怎样才能定位没有标题的项目行
protected void gv_timesheet_RowDataBound(object sender, GridViewRowEventArgs e)
{
//To check condition on date time
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "endTimeStamp")) == Convert.ToDateTime("0001-01-01 00:00:00.0000000"))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}
答案 0 :(得分:1)
您可以根据DataControlRowType.DataRow
if(e.Row.RowType == DataControlRowType.DataRow)
{
//To check condition on date time
if (Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "endTimeStamp")) == Convert.ToDateTime("0001-01-01 00:00:00.0000000"))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}