Eval in href anchor tag

What I'm trying to achieve is to use the Eval parameter in my href anchor tag. An anchor is built into the repeater, so I cannot use the code to achieve this.

I tried a few things with no luck.

<a href="http://MyWebsite/ActiveUsers?ID=InsertEvalHere"><%# Eval("Name")%></a>

The following code below is what I was trying to do:

<a href="<% "http://MyWebsite/ActiveUsers?ID=" + DataBinder.Eval(Container.DataItem("ID"))%>"><%# Eval("Name")%></a>

<a href="<% "http://MyWebsite/ActiveUsers?ID=" + Eval("ID")%>"><%# Eval("Name")%></a>

<a href="http://MyWebsite/ActiveUsers?ID=<% DataBinder.Eval(Container.DataItem("ID"))%>"><%# Eval("Name")%></a>

<a href="http://MyWebsite/ActiveUsers?ID=<%# Eval("ID")%>"><%# Eval("Name")%></a>

None of the above seemed correct, as I continue to receive this error - The tag is not formed.

How should I do it?

+5
source share
5 answers
<a href="<%# String.Format("http://MyWebsite/ActiveUsers?ID={0}", Eval("ID")) %>">
+24
source

Use this:

<a href='http://MyWebsite/ActiveUsers?ID=<%# Eval(Container.DataItem("ID"))%>'><%# Eval("Name")%></a>
+4
source

URL-

<a href='http://MyWebsite/ActiveUsers?ID=<% DataBinder.Eval(Container.DataItem("ID"))%>'><%# Eval("Name")%></a> 
+1

, ....

<a href='<%# Eval("ID","http://MyWebsite/ActiveUsers?ID={0}") %>'><%# Eval("Name")%></a>
0

If you need access to the anchor in the code to enable and disable it based on the condition in datalist_ItemDataBound, you can use the method provided by Nicky Waites , with a little change, as shown below

<a id="register" runat="server" href='<%# String.Format("http://MyWebsite/ActiveUsers?ID={0}", Eval("ID")) %>'>

Hope this helps someone.

0
source

All Articles