我想在用DateGrid显示数据时,来根据某个字段的不同值(0、1、2)来让DataGrid标题列的标题显示不同的颜色,实在搞不定了,请教一下各位了!

解决方案 »

  1.   

    在 DataBind() 之前 更改 Header 属性
      

  2.   

    http://expert.csdn.net/Expert/topic/2897/2897180.xml?temp=.1145136
      

  3.   

    protected void FormatDataGrid_ItemDataBound(object source, 
    System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
          //  确保处理的是数据行,而不是Header或者Footer
          if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
          {
            //  得到Manager字段的值
            string isManager = (string)DataBinder.Eval(e.Item.DataItem, "Manager");        if (isManager == "1")
            {
              // '  设定文字和背景颜色
            e.Item.Cells[2].Text = "经理"
            e.Item.Cells[2].Style.Add("font-weight", "bold")
            e.Item.Cells[2].ForeColor = System.Drawing.Color.Red
            e.Item.BackColor = System.Drawing.Color.AliceBlue
            }
            else
            {
              e.Item.Cells[2].Text = "普通员工";
            }
          }
        }
      

  4.   

    protected void MyDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if(e.Item.ItemIndex>=0 && e.Item.DataItem is DataRowView)
        {
    DataRowView row=(DataRowView)e.Item.DataItem;
    if(string.Compare(row["xmid"].ToString().Substring(1,1),"0")==0) 
    {
                int numj=e.Item.Cells.Count;
       for(int j=0;j<numj;j++)
      {
         e.Item.Cells[j].ForeColor=Color.Black;
         e.Item.Cells[j].BackColor =Color.SkyBlue;
        }
           }
        }
    }