jxycms
3/30/2017 - 3:49 AM

get child node count in transformation

get child node count in transformation

*create a cs file called CSTransformation.cs under App_code folder, copy code below to that file

namespace CMS.Controls
{
    public partial class CMSTransformation
    {
        public string ChildCount(object nodeId)
        {
            int nodeid = ValidationHelper.GetInteger(nodeId, 0);
            string childCount = "";
            if (!string.IsNullOrEmpty(nodeId.ToString()))
            {
                TreeProvider tp = new TreeProvider(SiteContext.CurrentUser);
                TreeNode node = tp.SelectSingleNode(nodeid);
                childCount = node.Children.Count().ToString();
            }

            return childCount;
        }
             
    }
}