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
            Else
                'Order Status - Closed
                e.Row.Cells(15).Text = "Closed"
                        e.Row.BackColor = Drawing.Color.Firebrick
                        
[CHANGE URL TEXT COLOR WHITE HERE]
                        
                  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.

THANKS!
GridViewHyperLinkFontColor.png
dpmoneyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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
0
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?
0
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.
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
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).
0
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.
0
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
ASP.NET

From novice to tech pro — start learning today.