开发者

How to pass parameters from Eval to href

<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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜