在数据库中一个字段的值: 1是显示红色,0是正常
在界面上,如果是1,DataGrid中的一行变为红色,0为不变色

解决方案 »

  1.   

    在datagrid1的ItemDataBound事件中:if 要判斷的字段的值=1 then
     e.Item.BackColor = System.Drawing.Color.Red
    end if
      

  2.   

    e.Item.Style.Add("bgcolor", "Red")这样也行
      

  3.   

    同意1楼,不过补充一下,在itemDataBound事件中,加入if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
    {
    if 要判斷的字段的值==1 then
     e.Item.BackColor = System.Drawing.Color.Red
    end if}
      

  4.   

    可以通过datagrd在绑定数据的ItemDataBound事件时候将这段脚本加入进去。具体代码如下:
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){
    e.Item.Cells[2].Attributes.Add
    ("onmouseover","this.style.backgroundColor='Red'");
    e.Item.Cells[2].Attributes.Add
    ("onmouseout","this.style.backgroundColor='原来的颜色'");
    }
      

  5.   

    public void Item_Bound(object sender,DataGridItemEventArgs e)

    if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {   
    int j;

    if(e.Item.ItemIndex == -1)
    return;
    i = i + 1;
    j = i % 2;
    if(j == 1)
    {
    e.Item.BackColor = Color.FromArgb(240,255,240);
    e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#f0fff0'");
    }
    else
    {
    e.Item.BackColor = Color.FromArgb(255,255,204);
    e.Item.Attributes.Add("onMouseOut","this.style.backgroundColor='#ffffcc'");
    } e.Item.Attributes.Add("onMouseOver","this.style.backgroundColor='#ffeeff'");
    e.Item.Style.Add("cursor","hand");
    e.Item.Attributes.Add("onclick","location.href='contents_up.aspx?contents_id=" + e.Item.Cells[0].Text + "&Code="+Code+"'");

    }
    }
      

  6.   

    if(e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
    {
    if(e.Item.Cells[4].Text==true.ToString()) 
    e.Item.BackColor = System.Drawing.Color.Red;
    }