Avatar of Jesper Christensen
Jesper Christensen

asked on 

Make dynamic ID in hyperlink

Hi.

I get an error if i try to name the ID from database:

<asp:HyperLink runat="server" ID='<%# Eval("URL").ToString() %>' NavigateUrl='<%# Eval("URL").ToString() %>' Text='<%# Eval("Navn") %>'></asp:HyperLink>

Is there a workaround?
.NET ProgrammingC#

Avatar of undefined
Last Comment
yogsoft
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

URL may contain invalid characters (eg. ?, &), thus you can not use as an ID string.
Does your table in the database contains a unique ID that you can use?
Alternative: You can leave the ID blank.
Avatar of yogsoft
yogsoft
Flag of India image

If you are using data control like GridView/DataGrid/Data Repeater you can add Hyperlink control dynamically in ItemDataBound/RowDataBound event. Where you can set control id and other properties dynamically.

Hope this has given you alternative solution.
Avatar of Jesper Christensen
Jesper Christensen

ASKER

mas_oz2003: I need to find the ID from the codebehind page to add a css class on the id.
The hyperlinks is categories from the database. When I click a category, the hyperlink need to be underlined or something like this

So thats why I need to have an ID.
<asp:HyperLink runat="server" ID='<%# Eval("ID").ToString() %>' NavigateUrl='<%# Eval("URL").ToString() %>' Text='<%# Eval("Navn") %>'></asp:HyperLink>
dosent work.

yogsoft: I am using a ListView. Is your solution also the worksround with listview?
ASKER CERTIFIED SOLUTION
Avatar of yogsoft
yogsoft
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo