|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
HyperLinkField and FindControlHi;
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? 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.)
Other interesting topics
DataMappingType in the DataSet Designer
UserControls and Collections Property I do I remove the style attribute from Image controls? Link to download a file. .NET 2.0 TreeView control vertical align problem Problem in designing layout of website dynamic controls UserControl project or website location in design time Gridview Pager Modes |
|||||||||||||||||||||||