C# Umbraco:在用户控件中列出子节点

C# Umbraco:在用户控件中列出子节点,c#,asp.net,umbraco,C#,Asp.net,Umbraco,我有一个用户控件,需要根据parentID返回子节点。我能够获取parentID,但不知道返回子节点的语法 获取子节点非常简单 不确定您的代码有多远,因此下面是一个包含各种选项的完整示例: using umbraco.presentation.nodeFactory; namespace cogworks.usercontrols { public partial class ExampleUserControl : System.Web.UI.UserControl {

我有一个用户控件,需要根据parentID返回子节点。我能够获取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();
        }
    }
}
使用umbraco.presentation.nodeFactory;
命名空间cogworks.usercontrols
{
公共部分类ExampleUserControl:System.Web.UI.UserControl
{
受保护的无效页面加载(对象发送方、事件参数e)
{
//如果只需要当前节点的子节点,请使用以下方法
var currentNode=Node.GetCurrent();
//如果需要基于ID的特定节点,请使用此方法(其中123=所需的节点ID)
var specificNode=新节点(123);
//要将子节点作为节点集合获取,请使用此方法
var childNodes=specificNode.Children;
//迭代节点集合示例
foreach(childNodes中的var节点)
{
Write(string.Format(“{0}
”,node.Name)); } //要将节点作为datatable获取,以便将其用于数据绑定,请使用此方法 var childnodesasdatable=node.ChildrenAsTable(); //数据绑定示例 GridViewOnPage.DataSource=ChildNodesAsDataable; GridViewOnPage.DataBind(); } } }