在我的网站中,我有一个带有 Gridview 的页面,用于显示一些数据。我捕获 RowDataBound 事件,以确定单元格中是否存在某些文本。如果是,我把它涂成绿色,否则我把它涂成红色。
这是问题所在:Gridview 只有水平网格线。当我更改 RowDataBound 中单元格的颜色时(我实际上是在更改类),网格线采用应用的颜色。无论我尝试什么(循环遍历所有单元格并设置边框颜色),我都无法将其还原。请帮忙。
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 2; i <= 3; i++)
{
if (e.Row.Cells[i].Text.Contains("monkey"))
{
e.Row.Cells[i].Attributes.Add("class", "monkey bold");
}
else
{
e.Row.Cells[i].Attributes.Add("class", "nomonkey bold");
}
}
}
}
样式如下:
.monkey
{
color: #009900;
border-color: black;
}
.nomonkey
{
color: red;
border-color: black;
}
边框颜色属性似乎没有效果。
GridView 定义为:
<asp:GridView ID="GridView2" runat="server" AllowSorting="False" GridLines="Horizontal" AutoGenerateColumns="false" CellPadding="4" OnRowDataBound="GridView2_RowDataBound" OnDataBound="GridView2_DataBound" CssClass="reportGrid">
<FooterStyle BackColor="#2F76B8" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#2F76B8" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFFFF" ForeColor="#222222" HorizontalAlign="Center" />