【问题标题】:Umbraco: List Child Nodes in User ControlUmbraco:在用户控制中列出子节点
【发布时间】:2009-07-07 20:15:42
【问题描述】:

我有一个用户控件,我需要在其中根据 parentID 返回子节点。我能够获取 parentID,但不知道返回子节点的语法。

【问题讨论】:

    标签: c# asp.net umbraco


    【解决方案1】:

    获取子节点非常简单。

    不确定您的代码有多远,所以这里有一个包含各种选项的完整示例:

    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();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      相关资源
      最近更新 更多