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
C#ASP.NETProgramming Languages-Other

Avatar of undefined
Last Comment
dylanone

8/22/2022 - Mon
lunadl

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

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

The server tag is not well formed.
lunadl

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"))%>'
Your help has saved me hundreds of hours of internet surfing.
fblack61
dylanone

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

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)>'

andrewjb

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)
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
dylanone

ASKER
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>                  
lunadl

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
lunadl

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dylanone

ASKER
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">


Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
lunadl

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

ASKER
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.

 
dylanone

ASKER
Thanks - I never got this one working 100% correctly but at least I have several ideas now!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.