2009-07-07 6 views
14

मेरे पास एक उपयोगकर्ता नियंत्रण है जिसमें मुझे parentID के आधार पर बाल नोड्स को वापस करने की आवश्यकता है। मैं parentid प्राप्त करने में सक्षम हूं, लेकिन बच्चे नोड्स लौटने के लिए वाक्यविन्यास नहीं जानता।उम्ब्राको: उपयोगकर्ता नियंत्रण में बाल नोड्स की सूची

उत्तर

17

बच्चे नोड्स प्राप्त करना बहुत सरल है।

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

सुनिश्चित नहीं हैं कि कितनी दूर आप अपने कोड के साथ कर रहे हैं तो यहाँ विभिन्न विकल्पों के साथ एक पूर्ण उदाहरण है