Dynamic Hyperlink Column

G

Guest

I have a data grid with a hyperlink column. The hyperlink is created by a
class that extracts the link from an XML Document. How can I populate the
hyperlink column in the data grid with the value (link) returned from my
class method?

I have to send the company ticker to the class in order to get the correct
link. I tried embedding the method into the NavigateURL property of the data
grid (i.e. NavigateUrl="GetCompanyLink(Ticker)") but that didn't work.

Thanks.
 
E

Elliot M. Rodriguez

Jason:

Theres a few things you can do.

If you have a strongly typed dataset and generate it from within VS.NET,
you can specify the link value via the URL Field dropdown box in the
datagrid's properties window.

But if you prefer to do it at runtime, you can populate it using the
datagrid's ItemCreated event.

The following example assumes the hyperlink column is at the end of each
datagriditem row, and that the Hyperlink column contains only the
Hyperlink control. I am using the PhotoPath column from the Northwind
database, which is in the format "http://blahblahblah.bmp".

Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim lnkText As HyperLink =
CType(e.Item.Cells(e.Item.Cells.Count - 1).Controls(0), HyperLink)
lnkText.NavigateUrl = e.Item.DataItem("PhotoPath").ToString

End If
End Sub
 
G

Guest

I think I solved my own question. I used the ItemDataBound event to set the
table cell based on the company.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top