2014-09-10 134 views
0
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函数更改行中特定列的颜色,如何设置整个行?如何更改整个GridView行的颜色

+0

如何对这样的事情'yourTasksGV.DefaultCellStyle.SelectionBackColor = Color.Blue;'' = yourTasksGV.DefaultCellStyle.SelectionForeColor Color.Red;' – MethodMan 2014-09-10 18:54:42

回答

2

行也有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"; 
} 
+0

谢谢。这就像一个魅力 – Si8 2014-09-10 19:24:19