tags:

views:

150

answers:

6

I have a question about display URL's that are stored in an SQL Server database.

Here is an example.
I have a field in a table called "Additionalinfo" which stores this information.

Company Name
1 Street Name, Suburb
Ph: 0000 0000
W: http://www.google.com

When I display this information on the page it displays the information fine, however it doesn't make the URL active. It just displays it as plain text.

I would like to display it like this:

Company Name
1 Street Name, Suburb
Ph: 0000 0000
W: http://www.google.com

Is there any way I could make the URL active without changing the text to input into the database?

Any help would be greatly appreciated.

A: 

You need to somehow wrap an anchor tag () around the URL. Either do this at entry or when it is displayed on the page. You'll need someway to detect the URL portion if you do it on display only. If you have a URL field that is used to help populate this column, that would be the easiest place to put that logic.

For display purposes, use Regular Expressions. Here are some examples (untested)

http://www.velocityreviews.com/forums/t122843-find-url-in-a-string.html

Store

http://www.google.com

as

<a href="http://www.google.com">http://www.google.com&lt;/a>

the HTML is getting a little broken when I post but I think you get the point.

Cody C
I wouldn't store the markup- i'd generate it at display time
Joel Coehoorn
A: 

Since you can't change what you have in the database I would do a replace when you display the URL. Check to see if the database item starts with http:// or based on the column that comes out of the database and then wrap it with the anchor tag.

Avitus
A: 

If you display the info in an rtf control it should make the url "active"

Mosquito Mike
A: 

For the last line, do something like this:

litUrl.Text = string.Format(@"W: <a href=""{0}"">{0}</a>", datareader["W"]);

Where litUrl is a literal control. Of course, that assumes something very like ASP.Net/C#. You really haven't shared what you're using to retrieve this data and put it on a page. Sharing your existing code would really help.

Joel Coehoorn
A: 

if you're using a controller which has an OnItemDataBound event you can do it in the code behind.

Hyperlink test;
test.NavigateUrl = [item from database];
test.Text = [whatever Text];
Jack Marchetti
A: 

You just need to write it in more detail...

Classic ASP:

Response.Write(theUrl)
Response.Write("<a href="""+theUrl+""">"+theUrl+"</a>")

PHP

echo(theUrl);
echo('<a href="' . theUrl . '">' . theUrl . '</a>');

Shout if you want another language...

Sohnee