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.
GA Cell(0).Text should work
"GaryB" <gb@.nospam.com> wrote in message
news:eEcN6QHwEHA.2728@.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
>
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" <gdurzi@.hotmail.com> wrote in message
news:%23GsshaHwEHA.1524@.TK2MSFTNGP09.phx.gbl...
>A Cell(0).Text should work
>
> "GaryB" <gb@.nospam.com> wrote in message
> news:eEcN6QHwEHA.2728@.TK2MSFTNGP12.phx.gbl...
>
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" <gdurzi@.hotmail.com>
wrote:
>A Cell(0).Text should work
>
>"GaryB" <gb@.nospam.com> wrote in message
>news:eEcN6QHwEHA.2728@.TK2MSFTNGP12.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.)
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-schang@.online.microsoft.com> wrote in message
news:Mo4ElNLwEHA.768@.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.)
>
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.)
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment