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

Discussion in 'ASP .Net' started by =?Utf-8?B?ZGF2aWQ=?=, Oct 14, 2005.

  1. 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
    =?Utf-8?B?ZGF2aWQ=?=, Oct 14, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?ZGF2aWQ=?=

    intrader Guest

    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/Mastering_DataBinding.asp
    intrader, Oct 14, 2005
    #2
    1. Advertising

  3. 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
    =?Utf-8?B?RWx0b24gVw==?=, Oct 14, 2005
    #3
  4. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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
    =?Utf-8?B?ZGF2aWQ=?=, Oct 14, 2005
    #4
  5. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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
    =?Utf-8?B?RWx0b24gVw==?=, Oct 14, 2005
    #5
  6. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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
    =?Utf-8?B?ZGF2aWQ=?=, Oct 14, 2005
    #6
  7. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    You can also look at following URL:

    http://msdn.microsoft.com/library/d...lumnclassdatanavigateurlformatstringtopic.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
    =?Utf-8?B?RWx0b24gVw==?=, Oct 14, 2005
    #7
  8. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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/d...lumnclassdatanavigateurlformatstringtopic.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
    =?Utf-8?B?ZGF2aWQ=?=, Oct 14, 2005
    #8
  9. 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
    =?Utf-8?B?RWx0b24gVw==?=, Oct 14, 2005
    #9
  10. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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
    =?Utf-8?B?ZGF2aWQ=?=, Oct 17, 2005
    #10
  11. RE: How to assign a column of URLs to Hyperlink Column of a DataGr

    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
    =?Utf-8?B?RWx0b24gVw==?=, Oct 17, 2005
    #11
  12. =?Utf-8?B?ZGF2aWQ=?=

    deandany

    Joined:
    Jun 24, 2006
    Messages:
    1
    Hi... this is the solution

    Hi,

    I am too late .. but this is a workable soultion

    Hyper_Column.DataTextField = "PSH_Project_SubName"
    Hyper_Column.DataNavigateUrlField = dsProjectDetail.Tables(0).Columns(22).ColumnName

    Both the above properties refer same dataset columns in different ways.. but work on the same dataset..

    I thought Datagrid should have such a proeperty and when i found it out myself was happy...

    be happy,
    Dany
    deandany, Jul 17, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?WVNSYW8=?=
    Replies:
    1
    Views:
    468
    avnrao
    May 31, 2004
  2. Kaidi
    Replies:
    5
    Views:
    455
    Andrew Thompson
    Jan 4, 2004
  3. davetichenor
    Replies:
    1
    Views:
    808
    Eliyahu Goldin
    Oct 30, 2006
  4. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    731
    Sriram Srivatsan
    Aug 12, 2008
  5. Dave
    Replies:
    0
    Views:
    926
Loading...

Share This Page