views:

924

answers:

1

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="

+5  A: 

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>
John Rasch
That what I actually did, but it did not seem to work. Putting NavigateUrl="~/Details.aspx?ID=<%# Eval("productID") %>" couse: Generation of designer file failed: The server tag is not well formed.When I change one set of quotes to single that it creates link Details.aspx?ID=<%# Eval('productID') %>
padn
Edit: You were correct as the initial method did not actually work, but the updated method does... "The value of the expression parameter must evaluate to a public property." Source: http://msdn.microsoft.com/en-us/library/4hx47hfe.aspx
John Rasch
That works fine now thanks
padn