sly_Chandan
sly_Chandan

Reputation: 3515

How to pass parameters from Eval to href

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

Upvotes: 1

Views: 9624

Answers (3)

Jay M
Jay M

Reputation: 57

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"))%>

Upvotes: 0

sly_Chandan
sly_Chandan

Reputation: 3515

I found the solution to my issue.Thanks.

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

Upvotes: 2

Tola Odejayi
Tola Odejayi

Reputation: 3059

Try removing the space between the # and the Eval.

Upvotes: 0

Related Questions