日期:2014-05-18  浏览次数:20515 次

GridView 改变行颜色
我现在从DropDownLis获取了颜色的名字,比如Red,Yellow并写入数据库,现在怎么把这个值绑定到GridView行上,使其行变颜色呢??

------解决方案--------------------
GridView控件实现根据条件改变单元行的颜色

C# code
38     protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
39     {
40         if (e.Row.RowType == DataControlRowType.DataRow)
41         {
42             string Salary = e.Row.Cells[3].Text.ToString();
43             if (Convert.ToDouble(Salary.Substring(1)) > 2000.00)
44             {
45                 e.Row.BackColor = System.Drawing.Color.Orange;
46             }
47         }
48     }

------解决方案--------------------
C# code

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.BackColor = Color.FromName("Red");//此处的Red替换成你从数据库中取的值
            }
        }

------解决方案--------------------
看了楼上的,改一下
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.RowStyle.BackColor = System.Drawing.Color.FromName(DropDownList1.SelectedValue);
}