Link to home
Start Free TrialLog in
Avatar of Sheritlw
SheritlwFlag for United States of America

asked on

Syntax problem in small conditional statement

I have a listview with an image control.
I store the path to the image in a sql server db.
I need to evaluate the path to make sure it isn't null.  If it is null I need to change images.
I have tried multiple combinations trying to get this to work with no luck.
I either receive an error that the ? cannot be used or an expression is expected.

 <asp:Image ID="imgLeft" ImageUrl='<%#Eval("BeforePicPath") == null ? Eval("BeforePicPath").ToString() : "../images2020/resume-photo.jpg" %>' runat="server" />

Open in new window


What am I doing wrong?

Thanks
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

try this
http://forums.asp.net/t/1306214.aspx/1

<%# DataBinder.Eval(Container.DataItem,"Col_3") == DbNull.Value ? (string)DataBinder.Eval(Container.DataItem, "Col_2") : (string)DataBinder.Eval(Container.DataItem, "Col_3") %

Open in new window

This worked For me with my dataset .
//C# Code
Text='<%# DataBinder.Eval(Container.DataItem,"id") == "" ? (string)DataBinder.Eval(Container.DataItem, "name") : (string)DataBinder.Eval(Container.DataItem, "id") %>'>

Open in new window

Avatar of Sheritlw

ASKER

The alternative image is not referenced in the database, it is in a folder, so I tried...

 <asp:Image ID="imgLeft" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"BeforePicPath") == DbNull.Value ? "../images2020/resume-photo.jpg" : DataBinder.Eval(Container.DataItem,"BeforePicPath") %>'  runat="server" />

Open in new window


and received the same error -  BC30201: Expression expected.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you