setting HyperLinkField visited color, how??

J

Jeff

ASP.NET 2.0

I'm wondering how to set the color of a visited HyperLinkField (the link
text) in a GridView??

Here is the markup of the HyperLinkField I have problems with:
<asp:HyperLinkField HeaderText="Subject" Text="Subject"
DataTextField="Subject" DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="~/Templates/View.aspx?id={0}"
HeaderStyle-CssClass="columnStyle" ItemStyle-CssClass="columnStyle" />

Okay, I've already tryed this:
a:visited{
color:green;
}
I cannot use this css code because it set the color on all visited link on
my webpage. That is something I don't want. I want to set the color of
visited links within a GridView only.

I also tryed this:
GridView a:visited
{
color:Orange;
} -> but that didn't change the color within my GridView, infact no links on
my webpage was affected by this css class

Any suggestions?

Best Regards!

Jeff
 
J

Juan T. Llibre

<table>
<tr>
<td class="url">
<asp:HyperLink ID="1" runat="server" NavigateUrl="some.aspx" >Some</asp:HyperLink>
</td>
</tr>
</table>

Then, in your style sheet :

..url a {
font-family: Arial;
font-size: 9px;
color: navy;
text-decoration: none;
}

..url a:visited {
color: red;
}

....or any variation of the above.
 
J

Jeff

Thanks for that example but I'm wondering about setting the visited color of
a HyperLinkField object (not a HyperLink object) in a GridView. I don't see
how to apply the example you provided to my scenario (okay I'm a newbie).

This is the markup of the HyperLinkField field in my webpage
<asp:HyperLinkField HeaderText="Subject" Text="Subject"
DataTextField="Subject"
DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="~/Templates/View.aspx?id={0}"
HeaderStyle-CssClass="columnStyle" ItemStyle-CssClass="columnStyle" />

Jeff
 
J

Jeff

Thanks for that example but I'm wondering about setting the visited color of
a HyperLinkField object (not a HyperLink object) in a GridView. I don't see
how to apply the example you provided to my scenario (okay I'm a newbie).

This is the markup of the HyperLinkField field in my webpage
<asp:HyperLinkField HeaderText="Subject" Text="Subject"
DataTextField="Subject"
DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="~/Templates/View.aspx?id={0}"
HeaderStyle-CssClass="columnStyle" ItemStyle-CssClass="columnStyle" />

Jeff
 
J

Juan T. Llibre

re:
I don't see how to apply the example you provided to my scenario

For example :

A:link { color: #265CC0; text-decoration:none; }
A:visited { color: #000080; text-decoration:none; }
A:active { color: #265CC0; cursor:hand; text-decoration:none; }
A:hover { color: #4D9FE1; cursor:hand; text-decoration:"underline"; }

Take a look at :

http://asp.net.do/faq/default.aspx

That's the css code I use to change the link colors at that FAQ site.
Of course, you can change those colors to any other colors you want

After you visit the page, copy the default.css file from your browser's cache and use it as
guidance.
All I do to include it is use this code in the masterpage :

<link href="default.css" type="text/css" rel="stylesheet" />

Summarizing, you don't have to do anything special or different.
Just use css styles as you'd use them in any other web page.

The HyperLink object behaves like a standard link and picks up css styles specified for links.
 
J

Jeff

Thanks for the examples but A:link { color: #265CC0;
text-decoration:none; } will as I understand it set the color on all links
on a webpage. This is not how I want it. I want only to set the color of
visited HyperLinkField (not HyperLink) links with in a GridView on my
webpage.

any suggestions??

Jeff
 
J

Juan T. Llibre

Can you set individual hyperlink visited colors in *any* other platform ?
You may be asking for what no platform can deliver.
 
K

Kevin Fernandes

Hi Jeff,
I'll take a stab at this, but no guarentees :)

If I understand correctly, you want to set the color of a "visited"
HyperLinkField.

The problem is that the VS designer does not expose a way to do this
directly. As explained before, you will need to set CSS styles manually
in order to accomplish this (I believe).

You are correct that using A:visited { color: red; } as is, will set the
color of all visited hyperlinks (A tags) to that color wherever they
might appear in the document or site (using the CSS). What you need to
do is classify the style more. For instance you know that a GridView
will generate a table so you could do something like this

table A:visited {color: red;}

This CSS will only affect A tags that appear in a table.

If this is too broad; you have multiple hyperlink columns and only want
one of them to be "red" and the rest remain the same or there are tables
that should not be affected at all, then you need to use CSS classes or
control ID references.

I think the ID references would be problematic with dynamically
generated HTML so CSS classes would be better.

For instance, if you had a GridView with two HyperLinkField columns and
you wanted one to be "green" when visited and the other to be "red" you
might have CSS styles like the following:

..MyGridView .HyperColRed A:visited {color:red;}
..MyGridView .HyperColGreen A:visited {color:green;}

Then in the GridView's properties set the CssClass property to
"MyGridView" and in the HyperLinkField properties, open the ItemStyle
and set the CssClass to either "HyperColRed" or "HyperColGreen".
Alternately, you can set the ControlStyle CssClass instead, this will
affect "ALL" controls in the column regardless of which template they
appear in (i.e. Header, Footer, Item, or Edit).

Unfortunately I cannot guarantee this will work properly if you are
using Auto Formatting on the GridView, or other controls. If you are,
you may have to view the generated HTML to see what HTML and CSS was
produced, then copy some or all of it into your own styles.

Anyway, I hoped this help answer your question and sorry for the long
winded response.
:)

Good luck!
Kevin F.
 
J

Jeff

Hey guys!

I've solved it by using ControlStyle, see the example below

<asp:HyperLinkField HeaderText="Subject" Text="Subject"
DataTextField="Subject" DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="~/Templates/View.aspx?id={0}"
HeaderStyle-CssClass="columnStyle" ItemStyle-CssClass="columnStyle" >
<ControlStyle CssClass="r" />
</asp:HyperLinkField >


a.r:visited
{
color:Lime;
}

Best regards!

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top