Text from a Hyperlink column in a datagrid

Discussion in 'ASP .Net' started by GaryB, Nov 2, 2004.

  1. GaryB

    GaryB Guest

    Does anyone have any idea how to get the text out of a hyperlink column in a
    web datagrid?

    It's a hyperlink column, not a template column so findcontrol does not work
    and there is no apparent name to look for.

    myGridItem.cells(0).controls(0) shows no text properties or anything that
    points to or contains the text.

    It seems quite hidden.

    G
     
    GaryB, Nov 2, 2004
    #1
    1. Advertising

  2. GaryB

    George Durzi Guest

    A Cell(0).Text should work


    "GaryB" <> wrote in message
    news:...
    > Does anyone have any idea how to get the text out of a hyperlink column in
    > a web datagrid?
    >
    > It's a hyperlink column, not a template column so findcontrol does not
    > work and there is no apparent name to look for.
    >
    > myGridItem.cells(0).controls(0) shows no text properties or anything that
    > points to or contains the text.
    >
    > It seems quite hidden.
    >
    > G
    >
     
    George Durzi, Nov 2, 2004
    #2
    1. Advertising

  3. GaryB

    GaryB Guest

    No, it does not. That's the whole point of the question. When a column is
    a hyperlink column, the text is not present in cell(n).text.
    G

    "George Durzi" <> wrote in message
    news:%...
    >A Cell(0).Text should work
    >
    >
    > "GaryB" <> wrote in message
    > news:...
    >> Does anyone have any idea how to get the text out of a hyperlink column
    >> in a web datagrid?
    >>
    >> It's a hyperlink column, not a template column so findcontrol does not
    >> work and there is no apparent name to look for.
    >>
    >> myGridItem.cells(0).controls(0) shows no text properties or anything that
    >> points to or contains the text.
    >>
    >> It seems quite hidden.
    >>
    >> G
    >>

    >
    >
     
    GaryB, Nov 2, 2004
    #3
  4. GaryB

    Scott Allen Guest

    Im my experiment it renders into the second control. You can cast
    item.Cells(0).Controls(1) to a HyperLink control to pull the Text and
    NavigateUrl properties.

    Indexing into the control array always makes me nervous. I don't know
    when MS might change how the controls render and that would break some
    code. If I need to dig something out I stick to templated columns with
    named controls. Know what I mean?

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/


    On Mon, 1 Nov 2004 17:55:20 -0700, "George Durzi" <>
    wrote:

    >A Cell(0).Text should work
    >
    >
    >"GaryB" <> wrote in message
    >news:...
    >> Does anyone have any idea how to get the text out of a hyperlink column in
    >> a web datagrid?
    >>
    >> It's a hyperlink column, not a template column so findcontrol does not
    >> work and there is no apparent name to look for.
    >>
    >> myGridItem.cells(0).controls(0) shows no text properties or anything that
    >> points to or contains the text.
    >>
    >> It seems quite hidden.
    >>
    >> G
    >>

    >
     
    Scott Allen, Nov 2, 2004
    #4
  5. Thanks for Scott's informative suggestion.

    Hi Gary,

    As Scott has mentioned, since the HyperLink columns will contain a
    HyperLink control in it's Cell, we need to retrieve the HyperLink control
    first , then access its properties. For example:

    private void btnSubmit_Click(object sender, System.EventArgs e)
    {
    foreach(DataGridItem dgi in dgData.Items)
    {
    HyperLink hl = dgi.Cells[0].Controls[0] as HyperLink;
    if(hl!=null)
    {

    Response.Write("<br>Text: " + hl.Text + " Link: " + hl.NavigateUrl);
    }
    }
    }

    thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Nov 2, 2004
    #5
  6. GaryB

    GaryB Guest

    Thats it! I knew it was in cells(3).controls(0) but I was looking for it
    directly there. Of course I have to dimension it as a hyperlink and there
    it is.
    Thanks.

    About what Scott said, do you think this kind of thing might change?
    Gary

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Thanks for Scott's informative suggestion.
    >
    > Hi Gary,
    >
    > As Scott has mentioned, since the HyperLink columns will contain a
    > HyperLink control in it's Cell, we need to retrieve the HyperLink control
    > first , then access its properties. For example:
    >
    > private void btnSubmit_Click(object sender, System.EventArgs e)
    > {
    > foreach(DataGridItem dgi in dgData.Items)
    > {
    > HyperLink hl = dgi.Cells[0].Controls[0] as HyperLink;
    > if(hl!=null)
    > {
    >
    > Response.Write("<br>Text: " + hl.Text + " Link: " + hl.NavigateUrl);
    > }
    > }
    > }
    >
    > thanks.
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
     
    GaryB, Nov 2, 2004
    #6
  7. Hi Gary,

    Thanks for the followup. Yes, Scott's worry is reasonable since the
    internal implemention of the datagrid's Buildin ColumnType may changed in
    new versions. So it's better that we use a custom Template Column and put a
    HyperLink control which has a specified "id" property so that we can
    reference it via "FindControl".
    Also, do need to put the following code when accessing sub controls via
    index on webform so as not to get "null reference exception.".
    HyperLink hl = dgi.Cells[0].Controls[0] as HyperLink;
    if(hl!=null)
    {

    }

    Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Nov 4, 2004
    #7
    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:
    627
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
  2. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    11
    Views:
    1,028
    deandany
    Jul 17, 2006
  3. davetichenor
    Replies:
    1
    Views:
    909
    Eliyahu Goldin
    Oct 30, 2006
  4. Earl Teigrob

    Making datagrid hyperlink column displays Link or Text???

    Earl Teigrob, Jan 19, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    183
    Earl Teigrob
    Jan 19, 2004
  5. Dave
    Replies:
    0
    Views:
    997
Loading...

Share This Page