Display hyperlink in datagrid

G

Guest

Hello -

I have an application that pulls website addresses (amongst other things)
from a SQL Server database via a search page. How do I display the website
as a hyperlink that can be clicked on by the user to take them to the site?

I have the following in my html code:

<asp:hyperlink id=hlWebsite runat=server
text= '<%# Container.DataItem("WebLink") %>' target="_blank">
</asp:hyperlink>

Apparently I'm missing something because that does not produce a clickable
link.

Any help will be greatly appreciated!
 
G

Guest

Hi Sandy,

You can use <asp:HyperLinkColumn > in <Columns> </Columns> of datagrid like
follows:

<Columns>
<asp:HyperLinkColumn HeaderText="Links" DataNavigateUrlField="WebLink" Text
="WebLink" Target="_blank"></asp:HyperLinkColumn>
</Columns>

HTH

Elton Wang
(e-mail address removed)
 
G

Guest

Here's a neat way. You've worked with the formatting of numbers, dates, etc?

Well, if you just dind the column and set the format as {0} then the
databinder replaces {0} with your value

If you format it as "Hello {0} World" then you'd get your value with Hello
Before it and World after it.

if you format your datacolumn as "<a href='{0}'>{O}</A>" then it will, yet
again, replace all of the {0} instances with your value

Internally, what's happening is the DataGrid is calling String.Format on
each value, using the value and the format string you're specifying. If you
want more info on what your options are, take a look at the String.Format
method.
 
G

Guest

Thanks Elton!
--
Sandy


Elton W said:
Hi Sandy,

You can use <asp:HyperLinkColumn > in <Columns> </Columns> of datagrid like
follows:

<Columns>
<asp:HyperLinkColumn HeaderText="Links" DataNavigateUrlField="WebLink" Text
="WebLink" Target="_blank"></asp:HyperLinkColumn>
</Columns>

HTH

Elton Wang
(e-mail address removed)
 
G

Guest

Thanks, David!
--
Sandy


David Jessee said:
Here's a neat way. You've worked with the formatting of numbers, dates, etc?

Well, if you just dind the column and set the format as {0} then the
databinder replaces {0} with your value

If you format it as "Hello {0} World" then you'd get your value with Hello
Before it and World after it.

if you format your datacolumn as "<a href='{0}'>{O}</A>" then it will, yet
again, replace all of the {0} instances with your value

Internally, what's happening is the DataGrid is calling String.Format on
each value, using the value and the format string you're specifying. If you
want more info on what your options are, take a look at the String.Format
method.
 

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,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top