Alex J
Alex J

Reputation: 1567

Resolving a url inside Listview ItemTemplate a href

The URL in the databound object contains something like "~/root/path/test.aspx?id=1". (code below). I want to do Page.ResolveUrl on it inside the ListView. Just can't get the syntax right. Can anyone help please?

<asp:ListView ID="DataLV" runat="server">

    <LayoutTemplate>
        <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
    </LayoutTemplate>

    <ItemTemplate>
         <a runat="server" href="Page.ResolveUrl(<%#Eval("URL")%>)">View full data</a>
    </ItemTemplate>

</asp:ListView> 

Upvotes: 0

Views: 1637

Answers (1)

James Johnson
James Johnson

Reputation: 46067

You need to bring the databinding tags (<%#) outside of the Page.ResolveUrl method, and use single quotes around the href attribute:

href='<%#Page.ResolveUrl(Eval("URL"))%>'

Upvotes: 1

Related Questions