Hi all!

I have a TreeView control, a Textbox and a Button.
When a push the button i want to create a new node as a child what i'm selected on the TreeView control.
Also I have an xml file as a datasource for TreeView.

My problem:
When i first add a node (push the button) the treeview has not been reloaded, but the xml file has been modified.
And when i add a second node, 2 nodes are created (the very first and this one )
So, where should i modify my code to see what i have been added first time?

This is my code:

private void selectMaxValue(XmlNode node, ref int maxValue)
if(maxValue maxValue = Convert.ToInt32(node.Attributes["value"].Value);
foreach( XmlNode tmp in node.ChildNodes)
selectMaxValue(tmp, ref maxValue);
protected void Button1_Click(object sender, EventArgs e)
if (TreeView1.SelectedNode != null && TextBox1.Text != "")
XmlDocument doc = new XmlDocument();
string fileName = Server.MapPath("~");
fileName += "/Categories.xml";
XmlNode root = doc.DocumentElement;
string path = TreeView1.SelectedNode.ValuePath;
XmlNode node = root.SelectSingleNode("/" + path);
XmlElement elem = doc.CreateElement( TextBox1.Text );
int max = 0;
selectMaxValue(root, ref max);
elem.SetAttribute("value", max.ToString());