Sheritlw
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.
What am I doing wrong?
Thanks
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" />
What am I doing wrong?
Thanks
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") %>'>
ASKER
The alternative image is not referenced in the database, it is in a folder, so I tried...
and received the same error - BC30201: Expression expected.
Thanks
<asp:Image ID="imgLeft" ImageUrl='<%# DataBinder.Eval(Container.DataItem,"BeforePicPath") == DbNull.Value ? "../images2020/resume-photo.jpg" : DataBinder.Eval(Container.DataItem,"BeforePicPath") %>' runat="server" />
and received the same error - BC30201: Expression expected.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
http://forums.asp.net/t/1306214.aspx/1
Open in new window