2013-12-19 104 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這個。