You need bind datagrid with data source:
dg.DataSource = dataSourceObject
dg.DataBind()
And specify link column's binding field:
Dim linkCol As HyperLinkColumn = CType(dg.Columns(link_index),
HyperLinkColumn )
linkCol.DataTextField = "URL_FIELD_NAME"
Or in DataGrid_ItemDataBound event:
using DataRowView object (e.Item.DataItem)
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
HyperLink link = CType(e.Item.Cells(link_Column_index).Controls(0), HyperLink)
link.NavigateUrl = drv("URL_FIELD_NAME").ToString
HTH
david said:
Thank you.
It is not completely clear to me. For example, I have a list of URLs, called
URLs which is a column of a dataset, and I have a column of hyperlink column,
link, in the datagrid, dg. Assume that these two columns have the same size.
In the design view, I have left the URL box empty for the hyperlink column in
the property builder.
Now in the code behide, I try to fill in the URL box (property item) for
each hyperlink column item after I got the list of URLs. Can I do the
following:
dg.Columns("link") = URLs
Does it make sense?
David
:
HI David,
In DataGrid_ItemDataBound event:
HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();
HTH
Elton Wang
:
Hi, all:
I need a help from you about DataGrid control.
I created a DataGrid, dg, in design view of .NET visual Stadio and use the
builder to add a Hyperlink column to dg.
I want to try to assign a column of URLs to this hyperlink column in
programming way (ie., dynamically assignment). However, I can not find a way
to continue doing it.
Do you have ideas about it? Thanks.
David