How to add hyperlink to aspx label?

Posted on 2009-02-18
Last Modified: 2013-12-17

I get a string from DB and display on aspx page as label.

I need to add a hyperlink to that label.

How can I do that?

I use VC#
<a href="test.aspx"><asp:Label ID="Label5" runat="server" /></a>

Open in new window

Question by:techques
    LVL 19

    Accepted Solution

    Not quite sure what it is you need.
    Can you show me all the information you have being returned from the database - is it just 1 column or 2?
    Also show me what html it is you want ultimatley rendered?
    Meanwhile it may be that you just need to use the Hyperlink Control:
    <asp:HyperLink ID="MyLink" runat="server"></asp:HyperLink>
    Then in code behind you go:
            MyLink.Text = "BBC";
            MyLink.NavigateUrl =;
    But of course you put in there the values from your database.
    LVL 8

    Assisted Solution


    label.Text = "this text <a href=\"page.aspx?param=x\">link</a>"

    Open in new window

    LVL 20

    Assisted Solution


    I'm not sure if that might work....

    coz label will render < as it is. ull have to use < instead something like this...

    label.Text = "this text &lt;a href=\"page.aspx?param=x\"&gt;link&lt;/a&gt;"

    Open in new window

    LVL 19

    Expert Comment

    Think you got mixed up a bit.  If you did want to do things using a label and not an actual hyperlink control then < and > are correct. < and > will escape these and output them in the rendered content and not treat them as html tags.
    LVL 19

    Expert Comment

    Thanks for the points techques but really you shouldn't have accepted what informaniac said as an answer as what he said is completeley 100% wrong!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now