• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1711
  • Last Modified:

How to add hyperlink to aspx label?

Hi

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

0
techques
Asked:
techques
  • 3
3 Solutions
 
daveamourCommented:
Hi
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 = http://www.bbc.co.uk;
But of course you put in there the values from your database.
0
 
isaackhaziCommented:

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

Open in new window

0
 
Obadiah ChristopherCommented:
@isaackhazi..

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

0
 
daveamourCommented:
informaniac:
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.
0
 
daveamourCommented:
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!
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now