我正在使用 VS2005 C# 服务器端
编程。
我想知道在 VS2005 版本
中,是否可以在满足条件时 高亮显示
GridView 中的一行?例如,如果数据库中该行的 Risk 列存储为 high,则该行将被 用红色突出显示
。
这是可能的吗?
编辑:
当前代码:
protected void GridView1_OnRowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// do your stuffs here, for example if column risk is your third column:
if (e.Row.Cells[3].Text == "H")
{
e.Row.BackColor = Color.Red;
}
}
}
我假设列单元格从0开始,所以我的单元格在第3个位置。但颜色仍然没有改变。 有人有任何想法吗?
.Text
会更适用,而不是RowDataBound
,因为该值实际上包含在控件中而不是单元格中,所以DataBinder.Eval
应该适合你。 - V4Vendetta