我设计一个Datagrid,我想要根据某一个列的值来判断行的文字的颜色,比如一个列,有run,stop,error,其中run所在的行文字是绿色的,stop是红色的,error是黄色的,程序如何编写,背景色不变?

解决方案 »

  1.   

    在Datagrid 的名字后 打.
    然后 通过提示 看看 哪个属性是设置颜色的 把那个给改一下 就好了
      

  2.   

    protected void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='LightGoldenrodYellow'") ; 
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")   ;
    e.Item.Style["cursor"] = "hand";
    e.Item.ForeColor=Color.Blue;
    if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=30 &&  Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <60)
    {
    e.Item.ForeColor =System.Drawing.Color.Green;
    }
    if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=60  && Convert.ToInt32(e.Item.Cells[6].Text.ToString()) <90)
    {
    e.Item.ForeColor =System.Drawing.Color.Indigo;
    }
    if(Convert.ToInt32(e.Item.Cells[6].Text.ToString()) >=90 && e.Item.Cells[6].Text.ToString()!=null)
    {
    e.Item.ForeColor =System.Drawing.Color.Red;
    }
     
    }
    }
      

  3.   

    和四楼差不多,在ItemDataBound事件里面,判断item的值,设置不同颜色。
      

  4.   

    可以绑定每一列的Color属性。这样不用编代码,可以直接根据数据库中的数据改变颜色。
      

  5.   

    同意楼上的,我门可以直接在run,stop,error的值设成颜色的值,然后赋予blackcolor
      

  6.   

    antiking(Q狼E行-吹雪留香一点红,孤城寻欢花满楼) 这个方法好我就是这样用的
      

  7.   

    你也可以把不同的列的值设成这样: <font color=red>value</font>