问题描述
我用 VS2005 C#服务器端
编码。
我很好奇,想知道在 VS2005版本
,是有可能高亮
在GridView一行当条件满足?例如。 红色如果列的危险是特定行存储为高在数据库中,该行会高亮显示。
I'm curious to know that in VS2005 version
, is it possible to highlight
a row in a GridView when a condition is met? E.g. If column Risk is stored as high in the database for that specific row, the row will be highlighted in Red
.
这可能吗?
编辑:
当前code:
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,但这种颜色依旧不改。
I assume column cell starts from 0, so mine is at cell 3. But the color still does not change.
任何人有任何想法?
推荐答案
对了,补充 OnRowDataBound =yourGridview_RowDataBound
到你的GridView。该事件被触发,每行的GridView。
Yes, add OnRowDataBound="yourGridview_RowDataBound"
to your gridview. This event gets triggered for every gridview row.
在code的背后,有这样的:
In the code behind, have this:
public void yourGridview_RowDataBound(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[2].Text == 'high')
{
e.Row.BackColor = Color.Red;
}
}
}
类似的东西。
这篇关于突出的GridView排当条件满足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!