In general, you cannot copy'n'paste some Windows Forms code into an ASP.NET project and expect it to work, because objects are not the same between both technologies.
A Windows Forms
TreeView
is not the same as an ASP.NET
TreeView
, even if they have the same name.
ASP.NET
TreeView
has a
FindNode(string)[
^] which returns a
TreeNode
if specified string is found, and otherwise returns
null
.
This would give:
foreach (string name in data)
{
if ((node = treeView.FindNode(name)) == null)
{
}
nodes = node.ChildNodes;
}
Note that an ASP.NET
TreeNode
does not have a
Nodes
property; instead it has a
ChildNodes
property.
You should always refer to the core documentation of the objects you intend to use:
TreeView Class (ASP.NET)[
^]
TreeNode Class (ASP.NET)[
^]