Server.UrlEncode an XPath Value

I'm using an asp:XmlDataSource element with an asp:Repeater and the following XPath element works fine, but I need to know how to Server.UrlEncode the output value:

<%#XPath("title") %>

Open in new window

For example if the value was 'Sony T100 Digital Camera'  I want to build an output url like this:

<a href="">Sony T100 Digital Camera</a>

When I tried to use something like the following, it gives a server exception error:

<a href="<%=Server.UrlEncode(XPath("url")) %>"><%#XPath("title") %></a>

Open in new window

Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.HttpServerUtility.UrlEncode(string)' has some invalid arguments

Using inline code, how can I get the XPath value of 'title' to be url encoded?
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
I believe that the problem is that the XPath method returns an object, so you need to convert it to a string:

<%=Server.UrlEncode(XPath("url").ToString()) %>
Amandeep Singh BhullarCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.