GridVie中e.Row.Cells[3].ForeColor 设置了之后。。为啥连框架的颜色都变了?我只想里面的字变颜色啊。
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;
}
}
}
[解决办法]
if (Convert.ToDecimal(e.Row.Cells[3].Text) > 0)
{
e.Row.Cells[3].Text="<font color='#FF0000'>e.Row.Cells[3].Text</font>";
e.Row.Cells[4].Text="<font color='#FF0000'>e.Row.Cells[4].Text</font>";
}
[解决办法]
<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>