concatenate text with a bound value in a gridview field

  • Thread starter Thread starter smccauslin
  • Start date Start date
S

smccauslin

URLs are stored in a database in a form similar to www.mysite.com.
When the user clicks on the link, it should launch a seperate window
and go to that site. Here's the code


<asp:HyperLink
ID="HyperLink1"
runat="server"
NavigateUrl='<%# Bind("URL") %>'
Text='<%# Bind("URL") %>'
Target="_blank"
</asp:HyperLink>

All of the URLs in the database do not have http:// at the beginning.
I'd rather do it programmatically so that when new records are added,
the user does not have to remember to type http:// Is there an easyway
to code this so it is added at runtime?

In pseudo-code, I want to accomplish this:

NavigateUrl='<%# "http://" + Bind("URL") %>'

so that the data has http:// at the beginning. I'm just not sure how
to code it and haven't been able to find any examples.

Any suggestions are welcome! Thanks!
 
smccaulsin,

<asp:HyperLink
ID="HyperLink1"
runat="server"
NavigateUrl='<%# Eval("URL", "http://{0}") %>'
Text='<%# Eval("URL") %>'
Target="_blank"
</asp:HyperLink>

Also... Bind is for 2 way data binding (display and updating), while Eval is
for display only.

Regards,

Rob MacFadyen
 
Rob,

Thanks. I knew it would be rather simple. Now I know what I need to
learn more about.
Once again, thanks!

Scott
 
Back
Top