毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> net技术 >> 正文

GridVie中e.Row.Cells[3].ForeColor设置后连框架的颜色都变了

更新时间:2012-5-21:  来源:毕业论文

protected void GridViewProfit_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  e.Row.Cells[0].Text = (e.Row.DataItemIndex + 1).ToString();

  if (Convert.ToDecimal(e.Row.Cells[3].Text) > 0)
  {
  e.Row.Cells[3].ForeColor = System.Drawing.Color.Red;
  e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
  }
  else if (Convert.ToDecimal(e.Row.Cells[3].Text) < 0)
  {
  e.Row.Cells[3].ForeColor = System.Drawing.Color.Green;
  e.Row.Cells[4].ForeColor = System.Drawing.Color.Green;
  }  }  }
最好用css,这样不仅让程序作了浏览器能干的更好的事,还导致样式不容易扩展。

<head runat="server">
    <title></title>
    <style>       
        .simtd
        {
            color: #fff;
            background-color: Blue;
        }
       
        .emptytd
        {
            color: #FFFF00;
            background-color: Green;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" CssClass="table" OnRowDataBound="GridView1_RowDataBound">
    </asp:GridView>
    </form>
</body>

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Text = (e.Row.DataItemIndex + 1).ToString();

            if (Convert.ToDecimal(e.Row.Cells[0].Text) > 2)
            {
                //e.Row.CssClass = ""; 定义整行的样式
                e.Row.Cells[0].CssClass = "simtd";
            }
            else
            {
                e.Row.Cells[0].CssClass = "emptytd";
            }        }    }

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©chuibin.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。