Binding a treeview to xml file

Posted by A4u6178 under Regular Expressions on 6/14/2011 | Points: 10 | Views : 2920 | Status : [Member] | Replies : 2
HI All,
I have a xml file and a treeview is binded with this xml file.(xml file is datasource for treeview)
i have binded the category dropdownlist to the xml file.(binded a node in Xml file)

Now i Need help in adding a sub categoy to the treeview, for a particular category selected in above category dropdownlist.
selecting a particular category from dropdownlist and a textbox to take name of subcategory from user on a button click i want the textbox value should be added to the particular category selected from dropdownlist.

Thanks & Regards;
aaa



Responses

Posted by: Ndebata on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can loop all nodes and check whether the node value matches with that of Dropdownlist.selectedvalue, then add a node under this node

void AddTreeNodeSelected(TreeNodeCollection Nodes,string ParentNodeValue,string NewNodeValue)
{
foreach (TreeNode item in Nodes)
{
if (item.ChildNodes.Count > 0)
AddTreeNodeSelected(item.ChildNodes,ParentNodeValue,NewNodeValue);
else if (!string.IsNullOrEmpty(item.Value) && item.NavigateUrl.Equals(CurrentPageName,ParentNodeValue))
{
item.ChildNodes.Add(new TreeNode(NewNodeValue));
break;
}
}
}

Then Call this method where you have to pass Nodes as Treeview1.Nodes, DropDownList1.SelectedValue, TextBox1.Text to this method.

Thanks,
Debata

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi sir,

Thanks , for reply and code snippet provided , em going thru ur code..
em attaching the files ...
pls find the attachments of design page and code file..
help me how to proceed from thereafter..
 Download source file

Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response