当条件满足时突出显示GridView行
我正在使用VS2005 C# Server-side
编码。当条件满足时突出显示GridView行
我很想知道,在VS2005 version
,是否有可能highlight
GridView条件满足时的行?例如。如果列风险存储为高在该特定行的数据库中,该行将为highlighted in Red
。
可能吗?
编辑:
当前代码:
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但颜色依然不改。
任何人有任何想法?
是的,将OnRowDataBound="yourGridview_RowDataBound"
添加到您的gridview。每个gridview行都会触发此事件。
在后面的代码中,有这样的:
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;
}
}
}
类似的东西。
你应该认购RowDataBound
事件,有你的列提风险高,则该行的BackColor
设为您的高亮颜色选择
If (e.Row.RowType == DataControlRowType.DataRow)
{
//DataBinder.Eval(e.Row.DataItem,"Risk"))
//if this is high then set the color
e.Row.BackColor = Drawing.Color.Yellow
}
行的网格,手抓牢的
使用RowDataBound事件。在这种情况下,你会得到可能会同意你的条件
void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Logic for High
if(e.Row.Cells[1].Text > 100)
//set color
e.Row.Attributes.Add("style", "this.style.backgroundColor = '#FFFFFF';");
}
}
在RowDataBound
尝试添加基于CSS:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
// searching through the rows
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(int.Parse(DataBinder.Eval(e.Row.DataItem,"Risk").ToString()) > 100)
{
e.Row.BackColor = Color.FromName("#FAF7DA"); // is a "new" row
}
}
}
请参阅'http:// blog.jerryleelajohn.com/2009/08/rowdatabound-vs2005.html' –
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.BackColor = Color.Yellow;
Label l1 = (Label)e.Row.FindControl("lblage");
if(Convert.ToInt32(l1.Text)>=30)
{
e.Row.BackColor = Color.Tomato;
}
}
如果您添加了对您的想法的描述,而不是简单的代码,这将会很有帮助。 –
没有,只OnDataBound得到射击一次这是不是你想要的。当您尝试OnRowDataBound时它显示任何错误吗? – S200
确保您的'GridView_OnRowDataBound'方法设置为'public'。 – S200
@RUHAHAO检查我的解决方案,我认为'.Text'将更适用于DataBound事件而不是'RowDataBound',因为该值实际上由控件包含,而不是单元,所以'DataBinder.Eval'应该适合您 – V4Vendetta