Forums

Forums / Developing Portals / Check for NULL in a CRM field

Check for NULL in a CRM field

Thread is closed for posting
5 posts, 1 answered
  1. philippe.devaux
    philippe.devaux avatar
    3 posts
    Registered:
    05 Jun 2015
    08 Jun 2015
    Link to this post
    Hi,

    I'm using a CRM List View and want to display the value of 2 different fields depending on the value of a specific field.
    I tried this, but this was not valid:

    <%#
    DataBinder.GetPropertyValue(Container.DataItem,"myfieldcouldneNULL")== NULL ? DataBinder.GetPropertyValue(Container.DataItem,"​showifNULL"): DataBinder.GetPropertyValue(Container.DataItem,"showifnotNULL")
    %>
  2. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    08 Jun 2015 in reply to philippe.devaux
    Link to this post
    Hello Philippe,

    Try one of the following suggestions below, note that to compare with null you must use lowercase "null":

    <%# DataBinder.GetPropertyValue(Container.DataItem,"myfieldcouldneNULL") == null ? DataBinder.GetPropertyValue(Container.DataItem,"​showifNULL") : DataBinder.GetPropertyValue(Container.DataItem,"showifnotNULL") %>
    
    <%# (String.IsNullOrEmpty(DataBinder.GetPropertyValue(Container.DataItem,"myfieldcouldneNULL")) ? DataBinder.GetPropertyValue(Container.DataItem,"​showifNULL") : DataBinder.GetPropertyValue(Container.DataItem,"showifnotNULL")) %>
    

    Regards,
    Clinton
    Last modified on 08 Jun 2015 17:06 by Clinton Bale
  3. philippe.devaux
    philippe.devaux avatar
    3 posts
    Registered:
    05 Jun 2015
    08 Jun 2015 in reply to Clinton Bale
    Link to this post
    When I do this, I get this error; I tried already with String.IsNullOrEmpty and string.IsNullOrEmpty

    Compiler Error Message: CS1502: The best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments

    <b><%#DataBinder.GetPropertyValue(Container.DataItem, "deelnemercontact.fullname") %></b>, <i><%# DataBinder.GetPropertyValue(Container.DataItem,"deelnemercontact.jobtitle") %></i> <%# (String.IsNullOrEmpty(DataBinder.GetPropertyValue(Container.DataItem,"stm_accountdeelnemerslijstid")) ? DataBinder.GetPropertyValue(Container.DataItem,"acm_accountid") : DataBinder.GetPropertyValue(Container.DataItem,"stm_accountdeelnemerslijstid")) %>
  4. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    08 Jun 2015 in reply to philippe.devaux
    Link to this post
    Try adding a .ToString() call after the DataBinder.GetPropertyValue call:

    <%# (String.IsNullOrEmpty(DataBinder.GetPropertyValue(Container.DataItem,"myfieldcouldneNULL").ToString()) ? DataBinder.GetPropertyValue(Container.DataItem,"​showifNULL") : DataBinder.GetPropertyValue(Container.DataItem,"showifnotNULL")) %>
    
    Last modified on 08 Jun 2015 17:06 by Clinton Bale
  5. philippe.devaux
    philippe.devaux avatar
    3 posts
    Registered:
    05 Jun 2015
    08 Jun 2015 in reply to Clinton Bale
    Link to this post
    Yes, that did the trick.
5 posts, 1 answered