Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building dynamic links with Repeater control

I am rendering data using Repeater control. Let's say there are 2 fields in the data source: productName and ProductID

In the following code:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<%#Eval("productName")%> <br/>
<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>

What do I need to modify in

<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl="~/Details.aspx?ID=">See Details</asp:HyperLink>

to include value retreived from the ProductID in the link NavigateUrl="~/Details.aspx?ID="

like image 423
padn Avatar asked Feb 10 '09 17:02

padn


1 Answers

NavigateUrl="~/Details.aspx?ID=<%# Eval("productID") %>" should work...

... but it doesn't!

The most elegant way should be:

<asp:HyperLink ID="lnkDetails" runat="server" NavigateUrl='<%# Eval("ProductID", "~/Details.aspx?ID={0}") %>'>See Details</asp:HyperLink>
like image 51
John Rasch Avatar answered Sep 29 '22 22:09

John Rasch