简单xml竖型菜单

1.截图
      
2.主要代码
  a>.aspx 页面的js
       <script language="javascript" type="text/javascript">
    function hidden(tableId,count)
    {
      tb=document.getElementById(tableId);
      tb.style.display="inline";
      for(i=0;i<count;i++)
      {
        if(i!==tableId)
        {
          document.getElementById(i).style.display="none";
        }
      }
    }
    function link(url)
    {
    
    
      window.parent.frames["frameRight"].location=url;
    }
    </script>

  b>.cs 文件
        protected void readXml()
    {
        XmlDataDocument xmlDoc = new XmlDataDocument();
        string path = Server.MapPath("TreeView2.xml");
        XmlTextReader xmlrd = new XmlTextReader(path);
        xmlDoc.Load(xmlrd);
        XmlNode xnode = xmlDoc.DocumentElement;
        for (int i = 0; i < xnode.ChildNodes.Count; i++)
        {
            tree.InnerHtml += "<div style='width:100%;border:1px double black;text-align:center;background-color:PowderBlue;padding:5px' onmouseover=javascript:this.style.background='LightSkyBlue';this.style.cursor='hand'  onmouseout=javascript:this.style.background='PowderBlue'  onclick='return hidden(" + i + "," + xnode.ChildNodes.Count + ")'>" + xnode.ChildNodes[i].Attributes["name"].Value + "</div>";
            tree.InnerHtml += "<table cellpadding='0' cellspacing='0' id='" + i + "' style='display:none;border:double 1px lightskyblue ;width:100%'>";
            for (int j = 0; j < xnode.ChildNodes[i].ChildNodes.Count; j++)
            {
                tree.InnerHtml += "<tr>";
                tree.InnerHtml += "<td style='border:double 1px lightskyblue ;text-align:center;width:100%;padding:5px'>";
                tree.InnerHtml += "<span style='color:red;' onmouseover=javascript:this.style.cursor='hand';this.style.textDecoration='underline' onmouseout=javascript:this.style.textDecoration='none'  onclick=link('" + xnode.ChildNodes[i].ChildNodes[j].Attributes["url"].Value + "')>";
                tree.InnerHtml += xnode.ChildNodes[i].ChildNodes[j].Attributes["name"].Value + "</span>";
                tree.InnerHtml += "</td></tr>";
              //xnode.ChildNodes[i].ChildNodes[j].Attributes["name"].Value);
            }
            tree.InnerHtml+="</table>";
        }
    
    }
posted @ 2007-09-25 00:52  koolay  阅读(338)  评论(0)    收藏  举报