Quote:
Originally Posted by julius
Hi People. I am currently facing a problem to allow a href on a Databind item. For example, The TextInput stated below will retrieve all the links posted by a user. For instance, if a user posted www.youtube.com or www.p2p.wrox.com , it will allow them to click on the Label and proceed to the link in a new window. Could someone advise me how to work on it?
Codes
<ahref=""><asp:LabelID="Label2"runat="server"Text='<%# Bind("TextInput") %>'></asp:Label></a><br/><br/>
|
I think you're looking for a nice simple solution and one that will give you good control over the HTML output. You're on the right track; the error indicates that "Bind" is a high powered method available on certain high powered controls. It's not available for the lighter controls like Label, you just need to use Eval.
You can even drop the span tag generated by the Label control by using the asp:Literal control instead. A label would render this as...
<a href="www.youtube.com"><span>www.youtube.com</span></a>
when what you really want is...
<a href="www.youtube.com">www.youtube.com</a>
and I believe using a literal with the Eval method should do the trick best.