Home All Groups Group Topic Archive Search About
Author
8 Apr 2006 3:47 PM
David Thielen
Hi;

I have a HyperLinkField inside my GridView and it works great. I use
DataNavigateUrlFields="ID"
DataNavigateUrlFormatString="Datasource.aspx?ID={0}" so I really want this
control.

However, I need to access this control in the RowDataBound in the
code-behind. There is no ID="name" for HyperLinkField so how do I get this
control in the code behind for each row?

And if I can't - then what control should I use to link to another page
passing an ID=123 in the url?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Author
10 Apr 2006 7:49 AM
Steven Cheng[MSFT]
Hi Dave,

Thank you for posting.

As for the Hyperlink field, since the hyperlink control within it is
autogenerated, so we can not reference it through ID, and one possible
approach is reference the control through control index, however, this is
dangerous and not recommended(you need to view the generated source(or use
some test code in RowDataBound event) to check the hyperlink control's
actual index).

For such scenario, I still think using TemplateField is the best choice.
And since VS IDE can help use convert a built-in column/field to a template
field, you can first define the hyperlink field (and make it work
correctly), then convert it to template field through IDE(in the
EditColumns wizard). Here is a sample TemplateField (in GridView) converted
from a HyperlinkField:

===========================
<asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("CategoryID", "DataSourcePage.aspx?id={0}") %>'
                            Text='<%# Eval("CategoryName", "[{0}]")
%>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:TemplateField>
============================

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Bookmark and Share