<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="title.aspx" title="根节点"  description="">
    <siteMapNode url="1111.aspx" title="1111"  description="" >
      <siteMapNode url="1.aspx" title="1-1"  description="" />
      <siteMapNode url="2.aspx" title="1-2"  description="" />
      <siteMapNode url="3.aspx" title="1-3"  description="" />
      <siteMapNode url="4.aspx" title="1-4"  description="" />
    </siteMapNode>
    <siteMapNode url="2222.aspx" title="2222"  description="" >
      <siteMapNode url="5.aspx" title="2-1"  description="" />
      <siteMapNode url="6.aspx" title="2-2"  description="" />
      <siteMapNode url="7.aspx" title="2-3"  description="" />
      <siteMapNode url="8.aspx" title="2-4"  description="" />
    </siteMapNode>
  </siteMapNode>
</siteMap>
C#
this.TreeView1.Nodes[0].ChildNodes[0].NavigateUrl = "aa.aspx";索引超出范围。必须为非负值并小于集合大小。
参数名: index

解决方案 »

  1.   

    C# 
    this.TreeView1.Nodes[0].ChildNodes[0].NavigateUrl   =   "aa.aspx"; 
    就是这条语句出错,出错提示为:
    索引超出范围。必须为非负值并小于集合大小。 
    参数名:   index
      

  2.   

    XmlDocument xmlDoc;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.TreeView1.ShowLines = true;
                this.LoadXmlTree();
            }
        }    public void LoadXmlTree()
        {
            xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("classXml.xml"));        XmlNodeList xnl = xmlDoc.SelectSingleNode("school").ChildNodes;
            TreeNode tn = new TreeNode();
            tn.Text = "school";
            tn.Value = "-1";
            tn.Expanded = false;
            this.TreeView1.Nodes.Add(tn);        foreach (XmlNode xn in xnl)
            {
                XmlElement xe = (XmlElement)xn;
                TreeNode tnC = new TreeNode();
                tnC.Text = xe.GetAttribute("name");
                tnC.Value = xe.GetAttribute("name");
                tnC.NavigateUrl = "";☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
                tnC.Expanded = true;
                tn.ChildNodes.Add(tnC);
                this.TreeNodeBind(xn.ChildNodes,tnC);
            }
        }    public void TreeNodeBind(XmlNodeList xnl,TreeNode tn)
        {
            foreach (XmlNode xnNext in xnl)
            {
                XmlElement xe = (XmlElement)xnNext;
                TreeNode tnNext = new TreeNode();
                tnNext.Text = xe.GetAttribute("id");
                tnNext.Value = xe.GetAttribute("sex");
                tnNext.Expanded = true;
                tn.ChildNodes.Add(tnNext);
                this.TreeNodeBind(xnNext.ChildNodes,tnNext);
            }
        }