If you want to add root node (parent node) then you can do it like this:
TreeNode node = CreateParentNode(NameOfnode, URL);
Your defination for CreateParentNode could be like this:
private TreeNode CreateMenuItem(string strText,int count, string strUrl)
{
TreeNode Node = new TreeNode();
try
{
////Create new menu item
////Set properties of the menu item, -1 for parent menu items
if (count != -1)
{
if (count != 0)
{
Node.Text = strText + "[" + count + "]";
Node.NavigateUrl = strUrl;
}
else
{
Node.Text = strText;
//Node.NavigateUrl = strUrl;
}
}
else
{
Node.Text = strText;
Node.NavigateUrl = strUrl;
}
return Node;
}
private TreeNode CreateMenuItem(string strText, string strUrl)
{
TreeNode Node = new TreeNode();
try
{
Node.Text = strText ;
Node.NavigateUrl = strUrl;
return Node;
}
Now node returned by this function can be added to your TreeView,
YourTreeView.Nodes.Add(node);
You also want to add child node under a parent, you need to have parent node:
You can retrive the parent node by index
TreeNode parent = TreeView.Nodes[index];
write a method to add childs:
private void AddChildMenuItems(string Text, string URL, TreeNode ParentNode)
{
TreeNode ChildNode = new TreeNode();
ChildNode = CreateParentNode(NameOfnode, URL); // First created
ParentNode.ChildNode.Add(ChildNode );
}
You can pass, input from dropdownlist. Once Item is added rebind your dropdown list.