I am trying to create a clickable image that when clicked, goes to a dynamic url. I have tried this a few ways but seem to be missing something.
<asp:TemplateField HeaderText="Copy">
<asp:ItemTemplate>
<a href="../PricingTool/PriceListCopy.aspx?PriceListID=<%# Eval("PriceListID") %>" runat="server" ID="lnkCopy" ><asp:Image runat="server" src="../../Images/plus.gif" /></a>
</asp:ItemTemplate>
</asp:TemplateField>
The above code causes a Parse error (The server tag is not well formed.)
<asp:TemplateField HeaderText="Copy">
<asp:ItemTemplate>
<asp:HyperLink runat="server" ID="lnkCopy" NavigateUrl="../PricingTool/PriceListCopy.aspx?PriceListID=<%# Eval("PriceListID") %>" ><asp:Image runat="server" src="../../Images/plus.gif" /></asp:HyperLink>
</asp:ItemTemplate>
</asp:TemplateField>
This above code gives me the same Parser error. Both errors occur on the asp:HyperLink and a href fields respectively.
Thanks.
This should work:-
<asp:TemplateField HeaderText="Copy">
<ItemTemplate>
<a href='<%# String.Format("../PricingTool/PriceListCopy.aspx?PriceListID={0}",
Eval("PriceListID")) %>' runat="server" id="lnkCopy">
<asp:Image runat="server" ImageUrl="../../Images/plus.gif" /></a>
</ItemTemplate>
</asp:TemplateField>
First of all you were mixing double quotes with single thus it was throwing error as soon as it encounters double quote present in Eval
method.
Apart from this, since you are using <asp:Image
no need to include HTML img tag again, you can directly assign the image in ImageUrl
property.