2013-12-19 225 views
2

我想根据某些条件更改gridview的特定行颜色,我在ASP.NET中使用c#。根据条件更改行的颜色

我知道我可以使用HTMLCellPrepared方法,但在我的方法中,我想查看其他网格的值以及?这可能吗?

protected void GVResults_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) 
    { 
     if (e.DataColumn.FieldName == "CarrierId") 
      if (Convert.ToInt32(e.CellValue) > 0) 
       e.Cell.ForeColor = System.Drawing.Color.Red;    
    } 

这是该方法的第一部分,但我想查看其他网格的值,以便对该网格进行可视化更改。问题是我不知道如何访问其他网格的值...

+0

是的,它是可能的但你的问题是过高的水平。请详细说明'某些条件'并且包含您已有的任何代码 – DGibbs

+0

@Dibib条件将基于来自另一个ASPXGridView的值和来自2个下拉列表的值。它有点复杂,但我只需要弄清楚如何从不同的ASPXGridview访问值 – jeffry

回答

4

我建议您使用htmlrowprepared事件来进行有条件着色的行。

根据你所编写的代码,下面的例子可以帮助你:

protected void GVResults_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e) 
    { 
     if (e.RowType != GridViewRowType.Data) return; 
     int value = (int)e.GetValue("CarrierId"); 
     if (value > 0) 
      e.Row.ForeColor = System.Drawing.Color.Red; 
    } 

参考:
Changing ASPxGridView Cell and Row Color on Condition

1

如果样式依赖于数据并为该条件设置样式,则可以使用GridView的RowDataBound事件来检查条件。

Here is an example这个。

相关问题