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"))%>
精彩评论