473,387 Members | 1,318 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Text from a Hyperlink column in a datagrid

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
Nov 18 '05 #1
6 1888
A Cell(0).Text should work
"GaryB" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
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" <gd****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
A Cell(0).Text should work
"GaryB" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #3
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" <gd****@hotmail.com>
wrote:
A Cell(0).Text should work
"GaryB" <gb@nospam.com> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #4
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.)

Nov 18 '05 #5
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-******@online.microsoft.com> wrote in message
news:Mo*************@cpmsftngxa10.phx.gbl...
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.)

Nov 18 '05 #6
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.)

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jib | last post by:
How do I redirect a hyperlink column's URL when the URL doesn't exist? Is it possible to set a default URL for the Hyperlink button? Thanks, Jib
1
by: Soul | last post by:
Hi, I have a column in my DataGrid which is a Hyperlink Column. Everything work fine except when I try to get the text of the column using this.DataGrid.SelectedItem.Cells.Text, I got blank...
3
by: Raja | last post by:
I have a datagrid, it has dropdown box as a column and i have one more column that has hyperlink. The NavigateURL for the hyperlink is to open a new window with a query stirng parameter as the...
6
by: epigram | last post by:
I'm using the DataGrid with AutoGenerateColumns set to false and choosing which columns I want in the grid by using the <Columns> attribute. What I want to do is to create a hyperlink out of one...
3
by: Tim::.. | last post by:
I currently have the following datagrid but want to turn the name and email column into a hyperlink in the codebehind! Can someone please tell me how I achieve this! Thanks Private Sub...
2
by: Jason | last post by:
I have a data grid with a hyperlink column. The hyperlink is created by a class that extracts the link from an XML Document. How can I populate the hyperlink column in the data grid with the...
10
by: david | last post by:
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...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
1
by: jeguillo | last post by:
I am trying to retrieve the text within each cell in a datagrid in order to change the color of each cell, depending on the value within that cell. This works fine on the cells that are bound...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.