Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Text from a Hyperlink column in a datagrid

Reply
Thread Tools

Text from a Hyperlink column in a datagrid

 
 
GaryB
Guest
Posts: n/a
 
      11-02-2004
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


 
Reply With Quote
 
 
 
 
George Durzi
Guest
Posts: n/a
 
      11-02-2004
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
>



 
Reply With Quote
 
 
 
 
GaryB
Guest
Posts: n/a
 
      11-02-2004
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
>>

>
>



 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      11-02-2004
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
>>

>


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-02-2004
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.)

 
Reply With Quote
 
GaryB
Guest
Posts: n/a
 
      11-02-2004
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]" <v-> 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.)
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-04-2004
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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink davetichenor ASP .Net 1 10-30-2006 02:57 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink Dave ASP .Net Datagrid Control 0 10-21-2006 07:48 PM
How to assign a column of URLs to Hyperlink Column of a DataGrid c =?Utf-8?B?ZGF2aWQ=?= ASP .Net 11 07-17-2006 07:20 PM
HyperLink Column and Button Column in a DataGrid =?Utf-8?B?V2FyYW4=?= ASP .Net 0 08-09-2005 12:00 AM
Making datagrid hyperlink column displays Link or Text??? Earl Teigrob ASP .Net Datagrid Control 0 01-19-2004 05:08 PM



Advertisments