Using @' and getting CS1003: Syntax error, '"' expected

dylanone
dylanone used Ask the Experts™
on
Does anyone see why this line below:

<fc:ConnectDisplay isvisible="<%# (((Publication) Container.DataItem).Title != @'no title')%>" runat="server">

would give this error:

Compiler Error Message: CS1003: Syntax error, '"' expected
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
use single quotes.. it is already a string... i believe that is how it works

<fc:ConnectDisplay isvisible='<%# (((Publication) Container.DataItem).Title != @'no title')%>' runat="server">

Author

Commented:
I actually had tried that - initially - I get with the above:

The server tag is not well formed.

Commented:
oh is 'no title' a field in the database or something? if so try this isvisible='<%# Eval("no title")%>' .. are you trying to get it to return true or false? If you are, then you want to disallow nulls in the DB or write a function that checks for them before writing the true/false here: isvisible='<%# isNullFunction(Eval("no title"))%>'
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Author

Commented:
'no title'  is text data that is appearing - and I'm trying to not get it to display.  

Commented:
ok then instead of using isNullFunction, make a isTitleFunction that tests for null, none, or exists then return true or false
 isvisible='<%# isTitleFunction(((Publication) Container.DataItem).Title)>'

Commented:
The string delimiter is " not '
So it should be
"no title"
rather than
'no title'

shouldn't it?

(Though this isn't winforms, which is my world, so maybe that's tosh)

Author

Commented:
So I wrote a simple - isTitleFunction below and I'm getting an odd error:
CS0030: Cannot convert type 'void' to 'bool'

which is this line that was added yesterday:
<fc:ConnectDisplay isvisible='<%# isTitleFunction(((Publication) Container.DataItem).Title)%>' runat="server">



<script language=C# runat=server>
            public void isTitleFunction(string e)
            {                  
                        
                  if(e != null)
                  {
                        e.Replace("no title","");
                                                
                  }
                  
                    
            }
</script>                  

Commented:
the type should be object and not string..it may be trying to cast an null to a string which throw an error.... try object e instead of string e... test for null then if it is not null then test the value.
Commented:
oh nevermind you need to return a bool value like this:

<script language=C# runat=server>
            public bool isTitleFunction(object e)
            {          
                  if(e != null)
                  {
                        return true;
                                               
                  }  
else
return false;
          }
</script>    

Author

Commented:
Good grief with all the above I get:

System.InvalidCastException: Specified cast is not valid.

The line below is what is states is the culprit:

<fc:ConnectDisplay isvisible='<%# isTitleFunction(((Publication) Container.DataItem).Title)%>' runat="server">


Commented:
take out (publication) thats the only casting???? i dunno.

Author

Commented:
It needs the publication because otherwise it can't find the Title

Compiler Error Message: CS0117: 'object' does not contain a definition for 'Title'

<fc:ConnectDisplay isvisible='<%# isTitleFunction((Container.DataItem).Title)%>' runat="server">

I'll play with it more tomorrow - if I still don't have it - I'll just give you the points - this appears to be one that could go on for a while but I think we're close.

 

Author

Commented:
Thanks - I never got this one working 100% correctly but at least I have several ideas now!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial