2011-11-22 52 views
1

我在我的一个gridview列中有一个值,它将确定整行的值是否应为红色。我做了下面,但不知何故每一行都是红色的。请提供建议。谢谢。根据列字段值更改gridview行forecolor

Protected Sub uigvList_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles uigvList.RowCreated 

    If e.Row.RowType = DataControlRowType.DataRow Then 
     If Not (DataBinder.Eval(e.Row.DataItem, "VoidOn")) Is Nothing Then ' This is the condition, if this field is not blank then I want to the entire row to have red colored values. 
      e.Row.BackColor = Drawing.Color.Firebrick 
     End If 
    End If 

End Sub 
+0

http://stackoverflow.com/questions/4867283/change-the-font-color-gridview-row-based-on-a-columns-value-cant-index-gridview –

+0

你可以尝试RowDataBound事件而不是RowCreated并将颜色应用于每个单元格,而不是一次将整个行应用,因为在某些浏览器中将颜色应用于行''标记无效 – Murtaza

回答

1

也许DBNull.Value

If (DataBinder.Eval(e.Row.DataItem, "VoidOn")) IsNot DBNull.Value Then ...
If e.Row.DataItem("VoidOn") IsNot DBNull.Value Then ...

PS:您可以在调试模式VoidOn值,只需设置断点的代码行。