Link to home
Create AccountLog in
Avatar of dylanone
dylanone

asked on

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

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
Avatar of lunadl
lunadl
Flag of United States of America image

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">
Avatar of dylanone
dylanone

ASKER

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

The server tag is not well formed.
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"))%>'
'no title'  is text data that is appearing - and I'm trying to not get it to display.  
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)>'

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)
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>                  
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.
ASKER CERTIFIED SOLUTION
Avatar of lunadl
lunadl
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
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">


take out (publication) thats the only casting???? i dunno.
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.

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