datagrid-how to get cell value(hyperlink column)

Discussion in 'ASP .Net' started by =?Utf-8?B?UGF1bA==?=, Oct 12, 2004.

  1. Hi I have a data grid with a hyperlink column. the colum has numbers like
    00001,000002, ect. Just wondering how to get the text value of the cell as
    tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    returns a blank string. It seems to work ok for the other columns that are
    just regular datagrid columns, not hyperlink types.
    Thanks.
    --
    Paul G
    Software engineer.
    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004
    #1
    1. Advertising

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

    Greg Burns Guest

    If you had a HyperLink in a template column I would use this:

    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    ListItemType.AlternatingItem Then
    With CType(e.Item.Cells(column number).FindControl("control name"),
    HyperLink)
    .ToolTip = "Foobar"
    .NavigateUrl = "Foobar"
    .Text="Foobar"
    End With
    End If

    But since you are using a HyperLinkColumn, I googled and found this:

    If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    ListItemType.AlternatingItem Then
    CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    End If

    HTH,
    Greg

    "Paul" <> wrote in message
    news:...
    > Hi I have a data grid with a hyperlink column. the colum has numbers like
    > 00001,000002, ect. Just wondering how to get the text value of the cell
    > as
    > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > returns a blank string. It seems to work ok for the other columns that
    > are
    > just regular datagrid columns, not hyperlink types.
    > Thanks.
    > --
    > Paul G
    > Software engineer.
    Greg Burns, Oct 12, 2004
    #2
    1. Advertising

  3. thanks for the information. Can this be in the page load routine as I am
    getting an error trying to use e.? Thanks Paul.

    "Greg Burns" wrote:

    > If you had a HyperLink in a template column I would use this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > With CType(e.Item.Cells(column number).FindControl("control name"),
    > HyperLink)
    > .ToolTip = "Foobar"
    > .NavigateUrl = "Foobar"
    > .Text="Foobar"
    > End With
    > End If
    >
    > But since you are using a HyperLinkColumn, I googled and found this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > End If
    >
    > HTH,
    > Greg
    >
    > "Paul" <> wrote in message
    > news:...
    > > Hi I have a data grid with a hyperlink column. the colum has numbers like
    > > 00001,000002, ect. Just wondering how to get the text value of the cell
    > > as
    > > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > > returns a blank string. It seems to work ok for the other columns that
    > > are
    > > just regular datagrid columns, not hyperlink types.
    > > Thanks.
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004
    #3
  4. Hi,
    I am getting an invalid cast on the following line, put it in a
    ItemDataBound event.
    CType(datagrid.Columns(0), HyperLinkColumn).Text = "foobar"
    just wondering if you may know what is wrong, thanks Paul.

    "Greg Burns" wrote:

    > If you had a HyperLink in a template column I would use this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > With CType(e.Item.Cells(column number).FindControl("control name"),
    > HyperLink)
    > .ToolTip = "Foobar"
    > .NavigateUrl = "Foobar"
    > .Text="Foobar"
    > End With
    > End If
    >
    > But since you are using a HyperLinkColumn, I googled and found this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > End If
    >
    > HTH,
    > Greg
    >
    > "Paul" <> wrote in message
    > news:...
    > > Hi I have a data grid with a hyperlink column. the colum has numbers like
    > > 00001,000002, ect. Just wondering how to get the text value of the cell
    > > as
    > > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > > returns a blank string. It seems to work ok for the other columns that
    > > are
    > > just regular datagrid columns, not hyperlink types.
    > > Thanks.
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004
    #4
  5. had the wrong column number.

    "Greg Burns" wrote:

    > If you had a HyperLink in a template column I would use this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > With CType(e.Item.Cells(column number).FindControl("control name"),
    > HyperLink)
    > .ToolTip = "Foobar"
    > .NavigateUrl = "Foobar"
    > .Text="Foobar"
    > End With
    > End If
    >
    > But since you are using a HyperLinkColumn, I googled and found this:
    >
    > If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > ListItemType.AlternatingItem Then
    > CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > End If
    >
    > HTH,
    > Greg
    >
    > "Paul" <> wrote in message
    > news:...
    > > Hi I have a data grid with a hyperlink column. the colum has numbers like
    > > 00001,000002, ect. Just wondering how to get the text value of the cell
    > > as
    > > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > > returns a blank string. It seems to work ok for the other columns that
    > > are
    > > just regular datagrid columns, not hyperlink types.
    > > Thanks.
    > > --
    > > Paul G
    > > Software engineer.

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004
    #5
  6. =?Utf-8?B?UGF1bA==?=

    Greg Burns Guest

    No. You have to use it in the ItemDataBound event of you datagrid.

    Greg

    "Paul" <> wrote in message
    news:...
    > thanks for the information. Can this be in the page load routine as I am
    > getting an error trying to use e.? Thanks Paul.
    >
    > "Greg Burns" wrote:
    >
    >> If you had a HyperLink in a template column I would use this:
    >>
    >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    >> ListItemType.AlternatingItem Then
    >> With CType(e.Item.Cells(column number).FindControl("control name"),
    >> HyperLink)
    >> .ToolTip = "Foobar"
    >> .NavigateUrl = "Foobar"
    >> .Text="Foobar"
    >> End With
    >> End If
    >>
    >> But since you are using a HyperLinkColumn, I googled and found this:
    >>
    >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    >> ListItemType.AlternatingItem Then
    >> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    >> End If
    >>
    >> HTH,
    >> Greg
    >>
    >> "Paul" <> wrote in message
    >> news:...
    >> > Hi I have a data grid with a hyperlink column. the colum has numbers
    >> > like
    >> > 00001,000002, ect. Just wondering how to get the text value of the
    >> > cell
    >> > as
    >> > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    >> > returns a blank string. It seems to work ok for the other columns that
    >> > are
    >> > just regular datagrid columns, not hyperlink types.
    >> > Thanks.
    >> > --
    >> > Paul G
    >> > Software engineer.

    >>
    >>
    >>
    Greg Burns, Oct 12, 2004
    #6
  7. Hi almost have it working but not quite. The hyperlink column has a
    different value for each row, data being returned from a stored procedure
    then going into a dataset.
    The code below returns the column text field of the hyperlink value but not
    the actual cell value. I have

    st_temp = CType(dg_searchlog.Columns(6), HyperLinkColumn).DataTextField
    and I get Data_Item_Number which is the correct text field selected in the
    data grid for that column but I need the cell values for each row out of the
    column.
    if I use
    st_temp = CType(dg_searchlog.Columns(6), HyperLinkColumn).Text
    it returns a blank string.
    "Greg Burns" wrote:

    > No. You have to use it in the ItemDataBound event of you datagrid.
    >
    > Greg
    >
    > "Paul" <> wrote in message
    > news:...
    > > thanks for the information. Can this be in the page load routine as I am
    > > getting an error trying to use e.? Thanks Paul.
    > >
    > > "Greg Burns" wrote:
    > >
    > >> If you had a HyperLink in a template column I would use this:
    > >>
    > >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> ListItemType.AlternatingItem Then
    > >> With CType(e.Item.Cells(column number).FindControl("control name"),
    > >> HyperLink)
    > >> .ToolTip = "Foobar"
    > >> .NavigateUrl = "Foobar"
    > >> .Text="Foobar"
    > >> End With
    > >> End If
    > >>
    > >> But since you are using a HyperLinkColumn, I googled and found this:
    > >>
    > >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> ListItemType.AlternatingItem Then
    > >> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > >> End If
    > >>
    > >> HTH,
    > >> Greg
    > >>
    > >> "Paul" <> wrote in message
    > >> news:...
    > >> > Hi I have a data grid with a hyperlink column. the colum has numbers
    > >> > like
    > >> > 00001,000002, ect. Just wondering how to get the text value of the
    > >> > cell
    > >> > as
    > >> > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > >> > returns a blank string. It seems to work ok for the other columns that
    > >> > are
    > >> > just regular datagrid columns, not hyperlink types.
    > >> > Thanks.
    > >> > --
    > >> > Paul G
    > >> > Software engineer.
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 12, 2004
    #7
  8. Looks like it is not possible to get the individual cell value of the
    hyperlink column when using a data text field data source. The .text member
    returns the string entered in the text entry of the property builder of the
    datagrid. Using this sets the text the same for each row of the hyperlink
    column. Setting the text field to a datasource will allow each row (cell
    text) to be different for the hyperlink column but there does not seem to be
    any method to return the value.

    "Greg Burns" wrote:

    > No. You have to use it in the ItemDataBound event of you datagrid.
    >
    > Greg
    >
    > "Paul" <> wrote in message
    > news:...
    > > thanks for the information. Can this be in the page load routine as I am
    > > getting an error trying to use e.? Thanks Paul.
    > >
    > > "Greg Burns" wrote:
    > >
    > >> If you had a HyperLink in a template column I would use this:
    > >>
    > >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> ListItemType.AlternatingItem Then
    > >> With CType(e.Item.Cells(column number).FindControl("control name"),
    > >> HyperLink)
    > >> .ToolTip = "Foobar"
    > >> .NavigateUrl = "Foobar"
    > >> .Text="Foobar"
    > >> End With
    > >> End If
    > >>
    > >> But since you are using a HyperLinkColumn, I googled and found this:
    > >>
    > >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> ListItemType.AlternatingItem Then
    > >> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > >> End If
    > >>
    > >> HTH,
    > >> Greg
    > >>
    > >> "Paul" <> wrote in message
    > >> news:...
    > >> > Hi I have a data grid with a hyperlink column. the colum has numbers
    > >> > like
    > >> > 00001,000002, ect. Just wondering how to get the text value of the
    > >> > cell
    > >> > as
    > >> > tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
    > >> > returns a blank string. It seems to work ok for the other columns that
    > >> > are
    > >> > just regular datagrid columns, not hyperlink types.
    > >> > Thanks.
    > >> > --
    > >> > Paul G
    > >> > Software engineer.
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 13, 2004
    #8
  9. =?Utf-8?B?UGF1bA==?=

    Greg Burns Guest

    Hmm. Sorry to hear that. Hadn't actually tried it.

    Personally, I would just switch and make that column a template column. Add
    a <asp:hyperlink runat=server id=MyHyperLink /> control and use FindControl
    to modify it in ItemDataBound.

    Greg


    "Paul" <> wrote in message
    news:...
    > Looks like it is not possible to get the individual cell value of the
    > hyperlink column when using a data text field data source. The .text
    > member
    > returns the string entered in the text entry of the property builder of
    > the
    > datagrid. Using this sets the text the same for each row of the hyperlink
    > column. Setting the text field to a datasource will allow each row (cell
    > text) to be different for the hyperlink column but there does not seem to
    > be
    > any method to return the value.
    >
    > "Greg Burns" wrote:
    >
    >> No. You have to use it in the ItemDataBound event of you datagrid.
    >>
    >> Greg
    >>
    >> "Paul" <> wrote in message
    >> news:...
    >> > thanks for the information. Can this be in the page load routine as I
    >> > am
    >> > getting an error trying to use e.? Thanks Paul.
    >> >
    >> > "Greg Burns" wrote:
    >> >
    >> >> If you had a HyperLink in a template column I would use this:
    >> >>
    >> >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    >> >> ListItemType.AlternatingItem Then
    >> >> With CType(e.Item.Cells(column number).FindControl("control name"),
    >> >> HyperLink)
    >> >> .ToolTip = "Foobar"
    >> >> .NavigateUrl = "Foobar"
    >> >> .Text="Foobar"
    >> >> End With
    >> >> End If
    >> >>
    >> >> But since you are using a HyperLinkColumn, I googled and found this:
    >> >>
    >> >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    >> >> ListItemType.AlternatingItem Then
    >> >> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    >> >> End If
    >> >>
    >> >> HTH,
    >> >> Greg
    >> >>
    >> >> "Paul" <> wrote in message
    >> >> news:...
    >> >> > Hi I have a data grid with a hyperlink column. the colum has
    >> >> > numbers
    >> >> > like
    >> >> > 00001,000002, ect. Just wondering how to get the text value of the
    >> >> > cell
    >> >> > as
    >> >> > tempstring = datagrid.Items(rownumber).Cells.Item(column
    >> >> > number).Text
    >> >> > returns a blank string. It seems to work ok for the other columns
    >> >> > that
    >> >> > are
    >> >> > just regular datagrid columns, not hyperlink types.
    >> >> > Thanks.
    >> >> > --
    >> >> > Paul G
    >> >> > Software engineer.
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Greg Burns, Oct 13, 2004
    #9
  10. ok sounds like a good idea. thanks.

    "Greg Burns" wrote:

    > Hmm. Sorry to hear that. Hadn't actually tried it.
    >
    > Personally, I would just switch and make that column a template column. Add
    > a <asp:hyperlink runat=server id=MyHyperLink /> control and use FindControl
    > to modify it in ItemDataBound.
    >
    > Greg
    >
    >
    > "Paul" <> wrote in message
    > news:...
    > > Looks like it is not possible to get the individual cell value of the
    > > hyperlink column when using a data text field data source. The .text
    > > member
    > > returns the string entered in the text entry of the property builder of
    > > the
    > > datagrid. Using this sets the text the same for each row of the hyperlink
    > > column. Setting the text field to a datasource will allow each row (cell
    > > text) to be different for the hyperlink column but there does not seem to
    > > be
    > > any method to return the value.
    > >
    > > "Greg Burns" wrote:
    > >
    > >> No. You have to use it in the ItemDataBound event of you datagrid.
    > >>
    > >> Greg
    > >>
    > >> "Paul" <> wrote in message
    > >> news:...
    > >> > thanks for the information. Can this be in the page load routine as I
    > >> > am
    > >> > getting an error trying to use e.? Thanks Paul.
    > >> >
    > >> > "Greg Burns" wrote:
    > >> >
    > >> >> If you had a HyperLink in a template column I would use this:
    > >> >>
    > >> >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> >> ListItemType.AlternatingItem Then
    > >> >> With CType(e.Item.Cells(column number).FindControl("control name"),
    > >> >> HyperLink)
    > >> >> .ToolTip = "Foobar"
    > >> >> .NavigateUrl = "Foobar"
    > >> >> .Text="Foobar"
    > >> >> End With
    > >> >> End If
    > >> >>
    > >> >> But since you are using a HyperLinkColumn, I googled and found this:
    > >> >>
    > >> >> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
    > >> >> ListItemType.AlternatingItem Then
    > >> >> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
    > >> >> End If
    > >> >>
    > >> >> HTH,
    > >> >> Greg
    > >> >>
    > >> >> "Paul" <> wrote in message
    > >> >> news:...
    > >> >> > Hi I have a data grid with a hyperlink column. the colum has
    > >> >> > numbers
    > >> >> > like
    > >> >> > 00001,000002, ect. Just wondering how to get the text value of the
    > >> >> > cell
    > >> >> > as
    > >> >> > tempstring = datagrid.Items(rownumber).Cells.Item(column
    > >> >> > number).Text
    > >> >> > returns a blank string. It seems to work ok for the other columns
    > >> >> > that
    > >> >> > are
    > >> >> > just regular datagrid columns, not hyperlink types.
    > >> >> > Thanks.
    > >> >> > --
    > >> >> > Paul G
    > >> >> > Software engineer.
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?UGF1bA==?=, Oct 13, 2004
    #10
    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?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    601
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
  2. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    11
    Views:
    1,009
    deandany
    Jul 17, 2006
  3. Replies:
    2
    Views:
    1,330
  4. davetichenor
    Replies:
    1
    Views:
    821
    Eliyahu Goldin
    Oct 30, 2006
  5. Dave
    Replies:
    0
    Views:
    935
Loading...

Share This Page