Bobney
Bobney

Reputation: 320

ASP.NET using Eval to get page / file name

How can I set the text value of a hyperlink to a the page or image name within a databound url string. Something like:

<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# Eval("attachUrl")%>' Text="<%# System.IO.Path.GetFileName(Eval("attachUrl"))%>"></asp:HyperLink>

The NavigateURL works but not the Text.

Upvotes: 1

Views: 1072

Answers (1)

James
James

Reputation: 82096

That's because you break the string when you add the " in the Eval method. Use apostrophe's on the outer text so you can use double-quotes for the Eval method i.e.

Text='<%# System.IO.Path.GetFileName(Eval("attachUrl").ToString())%>'

Upvotes: 3

Related Questions