To change the visited link color of asp:hyperlink in gridview

Last post 10-01-2008 7:22 PM by rperetz. 2 replies.

Sort Posts:

  • To change the visited link color of asp:hyperlink in gridview

    07-03-2008, 12:11 AM

    Hi all,

    I'm using vb.net 2.0 . In my page i have an asp:Hyperlink field in the gridview. The value for the hyperlink is taking from the database. And it's forecolour is set to green in the database..If i click on the link and then come back to this page it is not showing any visited color. i.e the color is still green even if that link is visited.  Can anyone tell me how to set the visited link color for this hyperlink. One more this i'm using master page in this page so to set style for this page i'm using "Themes" in the page directive.. Any one who knows the solution please help me...

     

    Thanks
    Swapna
    Please click "mark as answer" if this post helped you.
  • Re: To change the visited link color of asp:hyperlink in gridview

    07-03-2008, 1:47 AM
    Answer
    • All-Star
      28,218 point All-Star
    • johram
    • Member since 06-13-2006, 6:36 AM
    • Sweden
    • Posts 3,543
    • Moderator

    AFAIK, this is something you cannot express in your skin file. You need to do create a CSS file for your theme in which you can specify it.

    The trick is to use a pseudo-class for the a (anchor) selector. Example:

    a:visited { color: red; }

    If you place this in your theme CSS file, this will color all visited links in your web red. Now, I assume you would like to control this a little better to only apply for the links in the GridView for example. To do this, you either set a CSS class for the asp:HyperLink, using the CssClass attribute, or you do the same with the GridView (set the CssClass). Either way, you use the name of the css class in your css rule. This is to scope the rule to only apply in a this specific context. Example: 

    <asp:HyperLink CssClass="gwlink" runat="server" NavigateUrl="....."></asp:HyperLink>

    Then in your CSS file, you do:

    .gwlink a:visisted { color: red; }

    This will effectively render all visited links marked as gwlink in red.

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: To change the visited link color of asp:hyperlink in gridview

    10-01-2008, 7:22 PM
    • Member
      17 point Member
    • rperetz
    • Member since 07-27-2006, 11:48 AM
    • Posts 30

    sorry, but it did not work

Page 1 of 1 (3 items)