Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to replace all the spaces in my title to use as an ID, but I keep getting this error: error CS0103: The name 'Replace' does not exist in the current context

The code I am using is this: id="<%# Eval(Replace("Title"," ", "")) %>

id="<%# Eval("Title") %> works like a dream, and I have tried various ways to get the spaces removed, like Trim and Replace, but each gives me the above error.

can you help me format the right eval please? I am using SharePoint 2010 Enterprise edition.

Thanks Louise

share|improve this question
    
It seems like such a silly thing - but any .replace / .trims dont have definitions? –  Louise van der Bijl May 7 '12 at 13:00
    
id="<%# Eval("Title").Replace(" ", "") %>" brings back :error CS0117: 'object' does not contain a definition for 'Replace' –  Louise van der Bijl May 7 '12 at 13:03
add comment

2 Answers

My colleague gave me this ; id="<%# Eval("Title").ToString().Replace(" ", "") %>" and it worked! - Thanks for the help Christian!

share|improve this answer
add comment

could jQuery be an option for you? I think you can do this with an string replace function.

share|improve this answer
    
A friend suggested: String.Replace(Eval("Title"), " ", "") but I got this: error CS1501: No overload for method 'Replace' takes '3' arguments . Jquery is an option for me :) –  Louise van der Bijl May 7 '12 at 12:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.