Only write to page if property != null, in a PageList

Hi all!

I have a PageList and it lists propertys from child pages, like this.

<itemTemplate>
<%# Container.CurrentPage["EventDate"] %>
</itemTemplate>

Now, if the editor havent written anything in the property on the child's page type I dont want it to be written on the page. So, I tried

<% if (Container.CurrentPage["EventDate"] != null) { %>
      <%# Container.CurrentPage["EventDate"] %>
<% } %>

But that doesnt work. Neither does (because it is always null)

<% if (CurrentPage["EventDate"] != null) { %>
      <%# Container.CurrentPage["EventDate"] %>
<% } %>


How do I solve it? And please, as easy as possible! =) Thank you very much.


  • The intel says that 'System.ComponentModel.Container' will bind it, but it doesnt work!

  • Maybe something like this:

    ]]>

  • Johan: many many thanks. However that code gave some casting error. But I tried this and it worked:

    ]]>


    Can you also write this?

    ]]>

     

    There is however a little caveat. You see the code is like this really:



    ]]>


    So, if I also want to get rid of the h3? But you solution will certenly work, and Iam very gratefull. Thanks.

  • Ah! You can do like this:

    (""+Container.CurrentPage["EventDate"]).ToString() : string.Empty%>]]>

  • I just assumed EventDate was a DateTime-property... If it's just a short string:

    "" + Container.CurrentPage["EventDate"].ToString() + "" : string.Empty%>]]>

    Or use a PlaceHolder if you need your HTML more readable and not inside code blocks:

     


        <%# Container.CurrentPage["EventDate"] %>
     

  • Johan: Thank you!! Awesome. Splendid. So helpful. Have a superb day.

First   1   Last