我数据库里有一列为1,2,3,4,5,当某个值为1时此行在Gridview中的颜色为红,为2时颜色为绿......请教具体操作及代码.谢谢!

解决方案 »

  1.   

    改它的背景颜色就行了
    第一列
    for (int i = 0; i < this.dataGridView1.RowCount; i++)
                    {
                        if(this.dataGridView1.Rows[i].Cells[0].Value.ToString().Trim()=="1")
                            this.dataGridView1.Rows[i].Cells[0].Style.BackColor = Color.Red;
                        else if (this.dataGridView1.Rows[i].Cells[0].Value.ToString().Trim() == "2")
                            this.dataGridView1.Rows[i].Cells[0].Style.BackColor = Color.Green;                }.......
      

  2.   

    我想知道该如何改字体颜色...比方在ASP里面:
    if rs("id")=1 then
    <tr>
    <td>
    <font color="red">rs("a")</font>
    </td>
    <td>
    <font color="red">rs("b")</font>
    </td>
    <td>
    <font color="red">rs("c")</font>
    </td>
    </tr>
    end if
    if rs("id")=2 then
    <tr>
    <td>
    <font color="green">rs("a")</font>
    </td>
    <td>
    <font color="green">rs("b")</font>
    </td>
    <td>
    <font color="green">rs("c")</font>
    </td>
    </tr>
    end if....
    反正我就想用C#来表达上面的意思吧....谢谢!!!!