concatenate text with a bound value in a gridview field

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!
 
R

Rob MacFadyen

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
 
S

smccauslin

Rob,

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

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top