ASPX templates
Version 5.x > ASPX templates > Determine if Child Nodes Exist in Code-Behind View modes: 
User avatar
Member
Member
eric.rovtar - 1/20/2011 4:50:34 PM
   
Determine if Child Nodes Exist in Code-Behind
Hi!

What is the simplest way to determine if child nodes of a certain type exist for a document in code-behind?

For example, if a document has cms.files as direct children, I want to display a certain control. Basically:

if (CurrentDocument.HasNodesOfType("cms.file"))
{
myPanel.Visible = true;
}
else
{
myPanel.Visible = false;
}


Does that make sense?

Thanks!

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 1/24/2011 4:19:58 AM
   
RE:Determine if Child Nodes Exist in Code-Behind
Hi,

You can check whether some node has any children by using NodeChildNodesCount property. If there are any children, you can get the documents/nodes - their NodeParentID will be equal to the parent node ID and you can check their document type by NodeClassID where you will compare it to the class name ID of given document type.

I hope it makes sense.

Best regards,
Juraj Ondrus

User avatar
Member
Member
lwhittemore-emh - 1/27/2012 3:19:22 PM
   
RE:Determine if Child Nodes Exist in Code-Behind
how would you check if a child existed with a specific class in a transformation?

User avatar
Member
Member
lwhittemore-emh - 1/27/2012 3:23:28 PM
   
RE:Determine if Child Nodes Exist in Code-Behind
This is my code
<li class="<%# Eval("DocumentMenuClass") %>">
<a href="<%# GetDocumentUrl() %>">
<span>
<%# Eval("DocumentName") %>
</span>
</a>

<cc1:CMSRepeater ID="submenu1" runat="server" ClassNames="CMS.MenuItem" Path="./%" CacheMinutes="0" OrderBy="NodeOrder" TransformationName="healthysv.generic.listmenu">
</cc1:CMSRepeater>

</li>


What I am trying to do is wrap the nested repeater with <ul></ul> tags, but only when there are child documents that are cms.menuitem that are published

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/28/2012 9:37:38 AM
   
RE:Determine if Child Nodes Exist in Code-Behind
Hi,

you can use for example following code to check the class:

<%# Convert.ToBoolean(Eval("ClassName").ToString().Equals("CMS.News")) ? "news" : "NOT news"%>

Maybe you could check the hierarchical viewer web part, which could be suitable for your needs as well.

Best regards,
Ivana Tomanickova