更改背景颜色而不更改gridview的标题 [英] change the background color without change the header of the gridview

查看:123
本文介绍了更改背景颜色而不更改gridview的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了这段代码来改变行的颜色,如果endTimeStamp行的项目等于0001-01-01 00:00:00.0000000它改变了行,但也改变了头我想问我该如何针对没有标题的项目行

pre $ protected void gv_timesheet_RowDataBound(object sender,GridViewRowEventArgs e)
{
/ /要检查日期时间的条件
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;
}
}

解决方案

您可以添加基于条件的on DataControlRowType.DataRow

  if(e.Row.RowType == DataControlRowType.DataRow)
{
//检查日期时间条件
if(Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem,endTimeStamp))==转换。 ToDateTime(0001-01-01 00:00:00.0000000))
{
e.Row.BackColor = System.Drawing.Color.Red;
}
}


I have create this code to change the color of row if item of endTimeStamp row equal to "0001-01-01 00:00:00.0000000" it change the row but also change the header I wan to ask how can I target the item row without the header

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

解决方案

You can add condition - based on 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;
     }
  }

这篇关于更改背景颜色而不更改gridview的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆