如果用戶選擇了根父節點,該代碼示例下面應該努力來填充使用數據的集合樹:
保護無效ParseTreeNodes(對象發件人,System.Web.UI.WebControls.TreeNodeEventArgs E)
{
//Uncomment this line below and inspect the 'nodes' variable if you need to inspect all of the nodes
//var nodes = this.MyTreeView.Nodes;
//Some call to get data for example
var dataCollection = GetSomeDataForTheTree()
//Iterate through and create a new node for each row in the query results.
//Notice that the query results are stored in the table of the DataSet.
foreach (MyClassWithData data in dataCollection)
{
//Create the new node using the values from the collection:
TreeNode newNode = new TreeNode(data.LastName, system.ID)
{
//Set the PopulateOnDemand property to false, because these are leaf nodes
and do not need to be populated on subsequent calls.
PopulateOnDemand = false,
SelectAction = TreeNodeSelectAction.Select
};
//Add the new node to the ChildNodes collection of the parent node.
e.node.ChildNodes.Add(NewNode);
}
}
我添加了額外的代碼行來檢查當前節點的樹狀視圖,如果您有與父節點的問題或知道Nodes
集合中的具體數值。
代碼?錯誤消息的確切文本?它發生的線? –
@Steve Wellens:你有沒有讀過這個問題?我沒有收到任何錯誤消息。此外,您希望看到哪部分代碼? –