Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Null in custom table View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 1/7/2011 1:43:35 PM
   
Null in custom table
I have been trying hard on something, but everything I try seems to not work.

I have an image that I want to show only when the custom table field is not empty, but I can't seem to find the right way to check the field...

In my webpart (custom table repeater) I have this (I tried all the 3 different way):

<% if (Eval("PictureName") != "") { %>
<img src="<%= ResolveUrl(BaseUrl) %><%# Eval("PictureName") %>" align="left" />
<% } %>

<% if (Eval("PictureName") != null) { %>
<img src="<%= ResolveUrl(BaseUrl) %><%# Eval("PictureName") %>" align="left" />
<% } %>

<% if (Eval("PictureName") != DBNull.Value) { %>
<img src="<%= ResolveUrl(BaseUrl) %><%# Eval("PictureName") %>" align="left" />
<% } %>

I even tried some compares and other code I could find about null type but all I can notice is that the "null" returned by the Eval() doesn't even compare to null...

The PictureName field is a custom table data column that containes either a string with the image name or nothing (null). I have no problem to compare with database values normally but I think custom tables work differently?

How can I verify if it's null (or empty) successfully?

User avatar
Member
Member
Jeffrey H. - 1/7/2011 1:48:47 PM
   
RE:Null in custom table
Have you tried DataHelper.IsEmpty(Eval("PictureName")) ??

User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 1/7/2011 1:55:26 PM
   
RE:Null in custom table
I just tried it out with:

<% if (!DataHelper.IsEmpty(Eval("PictureName"))) { %>
<img src="<%= ResolveUrl(BaseUrlPictureName) %><%# Eval("PictureName") %>" align="left" />
<% } %>

and it returns false either with PictureName empty or not...

When I check in DEBUG mode, it either returns a "blabla.jpg" or null but I can't seems to get a hold of the null.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/10/2011 3:09:59 AM
   
RE:Null in custom table
Hi,

Which version/hotfix of Kentico CMS you are using? I have tried following code with 5.5 version and it works fine - it means - if the field is empty "no image" is displayed, otherwise, the image is displayed.

<%# IfEmpty(Eval("ItemText"), "no image", "<img src=\"" + Eval("ImagePath") + "\" />") %>


I do not know the type of your field used for storing the image. But if the GUID of this image is stored in the column you could use following code to generate complete code:
<%# GetImage("NewsTeaser") %> -Inserts a complete HTML code of the image stored in the column of the given name.

In this case your transformation code should look like:

<%# IfEmpty(Eval("ItemText"), "no image", GetImage("NewsTeaser")) %>

Best regards,
Ivana Tomanickova

User avatar
Certified Developer v7
Certified  Developer v7
Nathoushka - 1/10/2011 8:43:47 AM
   
RE:Null in custom table
I tried this and it works perfectly. It was a simple string like "image.jpg" that was stored.

Thanks!