tags:

views:

76

answers:

1

Hi

Problem: How to get Linq to make a default value of 'noImage.jpg' if null is returned from the database.

I'm querying a single table:

<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="Materials.MaterialsDataClassesDataContext"
    TableName="Materials" EnableDelete="True" EnableInsert="True" EnableUpdate="True">
</asp:LinqDataSource>

then displaying images:

<telerik:GridTemplateColumn HeaderText="Image" UniqueName="Image">  
                        <ItemTemplate>  
                            <a href="<%=VirtualPathUtility.ToAbsolute("~/")%>showFrontEndMaterialDetail.aspx?materialId=<%# Eval("Id")%>">
                            <img src="<%=VirtualPathUtility.ToAbsolute("~/")%>Images/Uploaded/Thumbs/<%# Eval("Image1") %>"></img></a>
                        </ItemTemplate>  
                     </telerik:GridTemplateColumn>

I thought I had it (but didn't) with:

<%# (string?)Eval("Image1") ?? "noImage.jpg" %>
A: 

How about

String.IsNullOrEmpty(Convert.ToString(Eval("Image1"))) ? "noImage.jpg" : Eval("Image1")
Tahbaza
Thanks Tahbaza.. http://stackoverflow.com/questions/3411155/c-eval-aspx-fun useful too to shorten to <%# Eval("Image1") ?? "noImage.jpg" %>
Dave