문제

ParentID를 기준으로 자식 노드를 반환 해야하는 사용자 컨트롤이 있습니다. 나는 부모를 얻을 수 있지만 자식 노드를 반환하기위한 구문을 모릅니다.

도움이 되었습니까?

해결책

자식 노드를 얻는 것은 매우 간단합니다.

코드가 얼마나 멀리 있는지 확실하지 않으므로 여기에는 다양한 옵션이있는 완전한 예가 있습니다.

using umbraco.presentation.nodeFactory;

namespace cogworks.usercontrols
{
    public partial class ExampleUserControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //If you just want the children of the current node use the following method
            var currentNode = Node.GetCurrent();

            //If you need a specific node based on ID use this method (where 123 = the desired node id)
            var specificNode = new Node(123);

            //To get the children as a Nodes collection use this method
            var childNodes = specificNode.Children;

            //Iterating over nodes collection example
            foreach(var node in childNodes)
            {
                Response.Write(string.Format("{0}<br />", node.Name));
            }

            //To get the nodes as a datatable so you can use it for DataBinding use this method
            var childNodesAsDataTable = node.ChildrenAsTable();

            //Databind example
            GridViewOnPage.DataSource = childNodesAsDataTable;
            GridViewOnPage.DataBind();
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top