Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...
I have a hyperlink control.I want to set id attribute with DataBinder.Eval(Container.DataItem, "ID").

How can I do this?

How to access this id from code behind?
Posted
Comments
Kornfeld Eliyahu Peter 2-Dec-14 7:03am    
Use server side (ASP.NET) control and not <a> tag...
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink%28v=vs.110%29.aspx
frend_rose 3-Dec-14 3:29am    
I am using server side control only
Sinisa Hajnal 2-Dec-14 7:08am    
If this is hyperlink control, it is server side control and you can assign the item in page_load. If it is part of the repeater item, use OnItemDataBound event.

From code-behind (Again assuming server control (runat="server") ) you just use the ID directly. Otherwise you have to FindControl("id")
frend_rose 3-Dec-14 3:10am    
yes..It is server side control... I am setting id as like this..
<asp:HyperLink id="<%# DataBinder.Eval(Container.DataItem, "ID") %>" runat="server" >
Praveen Kumar Upadhyay 2-Dec-14 8:15am    
The same question is been asked by the same person.

http://www.codeproject.com/Questions/848832/unable-to-parse-href-attribute-in-anchor-tag?arn=17

Buddy please take care of this

VB
try

ID='<%# DataBinder.Eval(Container.DataItem, "ID")%>'
 
Share this answer
 
Comments
frend_rose 3-Dec-14 3:34am    
tried the same..But it is giving the error as below

The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <
asp:Button runat="server" id="Button1" />
Assuming this is ID of the hyperlink within repeater control (since otherwise you could set fixed ID) use ItemDataBound event to set the ID instead of trying to bind it via EVAL.

Same goes for other types of list, just the event may be different.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900