更改背景颜色而不更改gridview的标题

时间:2012-09-26 18:48:10

标签: c# gridview

我已创建此代码以更改行的颜色如果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;
    }
}

enter image description here

1 个答案:

答案 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;
     }
  }