changing gridview backcolor using VB.net

GVNutrition =  is the Gridview name  that I want to change backcolor  of rows   to red when Risk Assessment column contains the word Positive.  P.S. Risk Assessment column pulls the values from  Test_Result (data source).

my current code is as shown below. But it doest change the backcolor to red. No change happens.

Sub GVNutrition_RowDataBound(sender As Object, e As GridViewRowEventArgs)

      If DataBinder.Eval(e.Row.DataItem, "Test_Result") = "Positive" Then
                  
                  e.Row.BackColor = System.Drawing.Color.Red
            End If
      
End Sub

Thank you for your time.
ocdcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robert SchuttSoftware EngineerCommented:
Your code for the RowDataBound event works fine for me. The problem must be somewhere else, like the way you fill the datasource or bind the event to the GridView. Can you post more code or have a look at what I did to reconstruct your problem?
aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="EE_Q_28506751_WEB._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> EE Q_28506751 </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GVNutrition" runat="server" OnRowDataBound="GVNutrition_RowDataBound">
        </asp:GridView>
    </div>
    </form>
</body>
</html>

Open in new window

code behind:
Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dt As New DataTable
        dt.Columns.AddRange({New DataColumn("Id", GetType(Integer)), New DataColumn("Description", GetType(String)), New DataColumn("Test_Result", GetType(String))})
        For i As Integer = 1 To 10
            dt.Rows.Add({i, "Item " & i, IIf(i Mod 3 = 0, "Negative", "Positive")})
        Next
        GVNutrition.DataSource = dt
        GVNutrition.DataBind()
    End Sub

    Sub GVNutrition_RowDataBound(sender As Object, e As GridViewRowEventArgs)

        If DataBinder.Eval(e.Row.DataItem, "Test_Result") = "Positive" Then

            e.Row.BackColor = System.Drawing.Color.Red
        End If

    End Sub

End Class

Open in new window

output:
capture of output
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.