Reputation: 6626
This works:
<asp:Label ID="asdf" runat="server" Text='<%# Eval("Image1") %>'></asp:Label>
displaying data like: L8_Pic_1.jpg
This doesn't:
<asp:Label ID="asdfaf111" runat="server" Text='<%# Eval("Image1").ToString() %>'></asp:Label>
It gives an Object Reference not set to an instance of an object error
I'm aiming to do this:
String.IsNullOrEmpty(Eval("Image1").ToString()) ? "noImage.jpg" : Eval("Image1")
Upvotes: 0
Views: 1001
Reputation: 18353
You're looking for the null coalesce operator. It allows you to do just that pattern with ??
:
<%# Eval("Image1") ?? "noImage.jpg" %>
This evaluates as: if Eval("Image1") is not null, return it, otherwise return "noImage.jpg".
Upvotes: 1