简体   繁体   English

锚标记 href 中的 eval

[英]eval in anchor tag href

What I am trying to achieve is to use an Eval as parameter in my anchor tag's href.我想要实现的是在我的锚标记的 href 中使用 Eval 作为参数。 The anchor is nested inside a repeater, why I cannot use the code behind to achieve this.锚嵌套在中继器内,为什么我不能使用后面的代码来实现这一点。

I have tried a few things without any luck.我已经尝试了一些没有任何运气的东西。

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

The following code below is what I have tried 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 to be right, as I keep getting this error - The tag is not well formed.以上似乎都不正确,因为我不断收到此错误 -标签格式不正确。

How should I handle this?我该如何处理?

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

用这个:

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

使用单引号并像这样将 url 移出

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

有点晚了但是......

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

If you need access the anchor in code behind for enabling and disabling it based on condition at datalist_ItemDataBound , then you can use the way provided by Nicky Waites with a small change as shown below如果您需要访问代码中的锚点以根据 datalist_ItemDataBound 的条件启用和禁用它,那么您可以使用Nicky Waites提供的方式,稍作改动,如下所示

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

Hope this would help someone.希望这会帮助某人。

In your repeater, use this:在你的中继器中,使用这个:

CommandName="Apikey" CommandArgument='<%#Eval("POAPI")%>'

And access in the code behind.并在后面的代码中访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM