By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

How to assign a column of URLs to Hyperlink Column of a DataGrid c

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Fri, 14 Oct 2005 08:53:14 -0700, david wrote:
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

Let's assume that you have the list in the dataset, dataview, array. You
can use DataBinding to provide your grid with values. For a good article:
http://www.codeproject.com/aspnet/Ma...ataBinding.asp

Nov 19 '05 #2

P: n/a
HI David,

In DataGrid_ItemDataBound event:

HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();

HTH

Elton Wang

"david" wrote:
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

Nov 19 '05 #3

P: n/a
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
"Elton W" wrote:
HI David,

In DataGrid_ItemDataBound event:

HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();

HTH

Elton Wang

"david" wrote:
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

Nov 19 '05 #4

P: n/a
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" wrote:
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
"Elton W" wrote:
HI David,

In DataGrid_ItemDataBound event:

HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();

HTH

Elton Wang

"david" wrote:
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

Nov 19 '05 #5

P: n/a
thanks

I will try it.

David

"Elton W" wrote:
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" wrote:
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
"Elton W" wrote:
HI David,

In DataGrid_ItemDataBound event:

HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();

HTH

Elton Wang

"david" wrote:

> 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

Nov 19 '05 #6

P: n/a
You can also look at following URL:

http://msdn.microsoft.com/library/de...tringtopic.asp

HTH

"david" wrote:
thanks

I will try it.

David

"Elton W" wrote:
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" wrote:
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
"Elton W" wrote:

> HI David,
>
> In DataGrid_ItemDataBound event:
>
> HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
> link.NavigateUrl = getURL();
>
> HTH
>
> Elton Wang
>
>
>
> "david" wrote:
>
> > 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

Nov 19 '05 #7

P: n/a
By the way, what does it mean by 0 in
HyperLink link = CType(e.Item.Cells(link_Column_index).Controls(0),
HyperLink) ?

Why use 0 in Control(0)? Can you explain this line of code?

Thanks

David

"Elton W" wrote:
You can also look at following URL:

http://msdn.microsoft.com/library/de...tringtopic.asp

HTH

"david" wrote:
thanks

I will try it.

David

"Elton W" wrote:
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" wrote:

> 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
>
>
> "Elton W" wrote:
>
> > HI David,
> >
> > In DataGrid_ItemDataBound event:
> >
> > HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
> > link.NavigateUrl = getURL();
> >
> > HTH
> >
> > Elton Wang
> >
> >
> >
> > "david" wrote:
> >
> > > 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

Nov 19 '05 #8

P: n/a
In a cell, there are one or more control(s), e.g. you can put a label and a
textbox or even just a white space (treated as Literal control).
Hence, cell.Controls(0) means first control, in your case Hyperlink control.
"david" wrote:
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

Nov 19 '05 #9

P: n/a
Hi, Elton:

in your sample code,
Dim linkCol As HyperLinkColumn = CType(dg.Columns(link_index),
HyperLinkColumn )

The link_index means the column index such as 0, 1, and so on, is that right?

Thanks

David
"Elton W" wrote:
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" wrote:
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
"Elton W" wrote:
HI David,

In DataGrid_ItemDataBound event:

HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
link.NavigateUrl = getURL();

HTH

Elton Wang

"david" wrote:

> 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

Nov 19 '05 #10

P: n/a
Yes

"david" wrote:
Hi, Elton:

in your sample code,
Dim linkCol As HyperLinkColumn = CType(dg.Columns(link_index),
HyperLinkColumn )

The link_index means the column index such as 0, 1, and so on, is that right?

Thanks

David
"Elton W" wrote:
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" wrote:
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
"Elton W" wrote:

> HI David,
>
> In DataGrid_ItemDataBound event:
>
> HyperLink link = (HyperLink)e.Item.Cells[link_Column_index].Controls[0];
> link.NavigateUrl = getURL();
>
> HTH
>
> Elton Wang
>
>
>
> "david" wrote:
>
> > 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

Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.