ASP.NET GridView Hyperlink Field Change URL Font Color in Code Behind (VB)

I have a VB ASP.NET GridView with the first column as a Hyperlink Field.  
Need to change font color of hyperlink text from standard blue to white in row databound event for just orders that are closed.
I'm already successfully changing cell background color to red in an If-Then statement.
Just need to change URL text to white.  Having issues since the URL field is treated differently.

Here is the code block and where I need to change the color:

'Order Status - Open
            If e.Row.Cells(15).Text.ToString = "False" Then
                e.Row.Cells(15).Text = "Open"
                        e.Row.Cells(4).BackColor = drawing.color.darkseagreen
                'Order Status - Closed
                e.Row.Cells(15).Text = "Closed"
                        e.Row.BackColor = Drawing.Color.Firebrick
                  End If

I can put in a line of code like this for the first column, but it does NOT change the color of the text because it is a hyperlink - has no effect:

                        e.Row.Cells(0).ForeColor = drawing.color.white

If I change the zero to a 1 or 2, it changes color of other cells fine.  The hyperlink field is causing the issue.

Who is Participating?
dpmoneyAuthor Commented:
I found a solution that worked perfectly.
Key was NOT using <asp:HyperLinkField>.
Instead, I used an <asp:TemplateField> with a <asp:Hyperlink> within it.
Once I did that, I could set an ID for the <asp:Hyperlink> field.
In the rowdatabound, I was able to then reference that ID via dim hl as new hyperlink) and findcontrol with ID I just set earlier.
Once I did that, I was able to set the forecolor without CSS.

hl.forecolor = drawing.color.white

Thanks for your time, balagangadhar T.
balagangadhar TCommented:
For this you have to create a  css class as below
a:link {
    color: red;

/* visited link */
a:visited {
    color: green;

/* mouse over link */
a:hover {
    color: hotpink;

/* selected link */
a:active {
    color: blue;
Then in row data bound event for your code do the following
   e.Row.Cells(15).Text = "Closed"
                        e.Row.FindControl(controlid).cssclass = "a:link"

If you want to change the color then just mention the color in a:link class
dpmoneyAuthor Commented:
I played around with this over the weekend and also came up with a CSS solution.  However, it did the same thing you code snippet is doing....applying the white hyperlink font to EVERY row in the grid view.   Even the rows that are designated as OPEN vs. CLOSED.  That is strange since we are doing the CSS assignment in the If|Then block where it does one thing vs. another based on whether order is open or closed.  Can you think of why it is applying the white font to every hyperlink vs. just the CLOSED rows?
balagangadhar TCommented:
It is good that you figured out. But you never mentioned that you are not using the hyperlink. I assumed that you are using the hyperlink and that is why i have mentioned the code e.Row.FindControl(controlid).
dpmoneyAuthor Commented:
The only solution provided by a community member did not work as required.  

Further research allowed me to figure out a solution on my own.
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.

All Courses

From novice to tech pro — start learning today.