如何更改整个GridView行的颜色

时间:2014-09-10 18:50:12

标签: c# asp.net gridview

protected void yourTasksGV_RowDataBound(object sender, GridViewRowEventArgs e)
{


    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        System.Web.UI.WebControls.ImageButton btnShowDepend = e.Row.FindControl("btnShowDepend") as System.Web.UI.WebControls.ImageButton;
        if (!string.IsNullOrEmpty(e.Row.Cells[5].Text))
        {
            if (DateTime.Parse(e.Row.Cells[5].Text).Date < DateTime.Now.Date)
            {
                e.Row.Cells[5].ForeColor = Color.FromName("#C00000");
                e.Row.Cells[5].ToolTip = "Task is Past Due";
                //instead of column per row, set every row that matches the condition to that color
            }
            else if (DateTime.Parse(e.Row.Cells[5].Text).Date <= DateTime.Now.AddDays(inDateOffset).Date)
            {
                e.Row.Cells[5].ForeColor = Color.FromName("#DCA704");
                e.Row.Cells[5].ToolTip = "Task is at Risk";
                //instead of column per row, set every row that matches the condition to that color
            }
            else
            {
                e.Row.Cells[5].ToolTip = "Task is Not Due Yet";
            }
        }
    }
}

不使用Date函数更改行中特定列的颜色,而是如何设置整个ROW?

1 个答案:

答案 0 :(得分:2)

Row也有ForeColor和Tooltip属性。只是做

if (DateTime.Parse(e.Row.Cells[5].Text).Date < DateTime.Now.Date)
{
   e.Row.ForeColor = Color.FromName("#C00000");
   e.Row.ToolTip = "Task is Past Due";
}