This is the all code. Very simple and short. I need to
populate a treeView in aspx page (web form) from XML file.
I get en completion error:No overload for
method 'TreeNode' takes '1' arguments .
using System;
using System.Web.UI.WebControls;
using Microsoft.Web.UI.WebControls;
using System.Xml;
namespace PopulateTVTest
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView treeView1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler
(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs
e)
{
// SECTION 1. Create a DOM Document and load the XML data
into it.
XmlDocument dom = new XmlDocument();
dom.Load("D:/Dirs_3.xml");
// SECTION 2. Initialize the TreeView control.
treeView1.Nodes.Clear();
treeView1.Nodes.Add(new TreeNode
(dom.DocumentElement.Name));--> error: No overload for
method 'TreeNode' takes '1' arguments
TreeNode tNode = new TreeNode();
tNode = treeView1.Nodes[0];
// SECTION 3. Populate the TreeView with the DOM nodes.
AddNode(dom.DocumentElement, tNode);
//treeView1.ExpandAll();
}
private void AddNode(XmlNode inXmlNode, TreeNode
inTreeNode)
{
XmlNode xNode;
TreeNode tNode;
XmlNodeList nodeList;
int i;
// Loop through the XML nodes until the leaf is reached.
// Add the nodes to the TreeView during the looping
process.
if (inXmlNode.HasChildNodes)
{
nodeList = inXmlNode.ChildNodes;
for(i = 0; i<=nodeList.Count - 1; i++)
{
xNode = inXmlNode.ChildNodes[i];
inTreeNode.Nodes.Add(new TreeNode(xNode.Name)); --> error:
No overload for method 'TreeNode' takes '1' arguments
tNode = inTreeNode.Nodes[i];
AddNode(xNode, tNode);
}
}
else
{
// Here you need to pull the data from the XmlNode based
on the
// type of node, whether attribute values are required,
and so forth.
inTreeNode.Text = (inXmlNode.OuterXml).Trim();
}
}
}
}
thank you very much!