开发者

How to pass parameters from Eval to href

开发者 https://www.devze.com 2023-01-29 17:31 出处:网络
<a runat=\"server\"开发者_JS百科 id=\"link\" href=\'ProductDetails.aspx?ID=<%# Eval(\"productID\") %>\'></a>
<a runat="server"开发者_JS百科 id="link" href='ProductDetails.aspx?ID=<%# Eval("productID") %>'></a>


I found the solution to my issue.Thanks.

<a runat="server" id="link" href='<%# Eval("productid", "ProductDetails.aspx?ID={0}") %>'><%# Eval("productname") %></a>


Try removing the space between the # and the Eval.


Just put the entire string within the <%# %> block.

<a runat="server" id="link" 
    href=<%# "ProductDetails.aspx?ID=" + Eval("productID") %>
</a>

As an added note, I'd recommend using HttpUtility.HtmlEncode so that if there's a character such as '%', your link won't break.

<a runat="server" id="link" 
    href=<%# "ProductDetails.aspx?ID=" + HttpUtility.HtmlEncode(Eval("productID"))%>

0

精彩评论

暂无评论...
验证码 换一张
取 消