我将Treeeview控件的属性TreeNodeSrc设置成files/menu.xml,则运行时会自动将menu.xml定义的各个节点生成一个树,如果将该属性的值清空,在CS程序中的private void Page_Load(object sender, System.EventArgs e)定义Treeview1.TreeNodeSrc=@"C:/Inetpub/wwwroot/ICBC_FJ/files/menu.xml",Treeview的树为空,请问是哪里出错了?

解决方案 »

  1.   

    http://msdn.microsoft.com/library/default.asp?url=/workshop/WebControls/webcontrols_entry.asp
      

  2.   

    因为没有看到你的XML文件,不好判断!
    但我推荐你用以下的方法:
    1.先将XML文件读入到DataSet中,用ReadXml等方法。
    2.在针对DataSet操作TreeView控件,这样你好控制你的程序。
    完全交给Treeview来管理XML是有缺陷的,要用自己的编码好控制!
      

  3.   

    Data Binding with XML and XSL TemplatesIn certain scenarios, it may be necessary to use XML data that is read-only, and it may also be in a format that cannot be directly used to data bind to the TreeView. The TreeView also supports Extensible Stylesheet Language (XSL) templates, which can be used to transform an XML file into a the correct format and structure. XSL can be used to transform XML files for data binding with both the TreeNode and TreeNodeType elements.The following example shows how XML and XSL can be used to populate a TreeView.Here is the up for the TreeView element, which binds to an XML file, nodes.xml, and an XSL file, template.xsl.<myxmltree:treeview
      id="tree1"
      runat="server"
      TreeNodeSrc = "nodes.xml"
      TreeNodeXsltSrc = "template.xsl"
    />
    The nodes.xml file contains the following:<?xml version="1.0" ?>
    <HelpTOC>
       <HelpTOCNode Title="Web Sites">
          <HelpTOCNode Title = "Microsoft" Url = "http://www.microsoft.com">
          </HelpTOCNode>
          <HelpTOCNode Title = "MSDN" Url = "http://msdn.microsoft.com">
          </HelpTOCNode>
       </HelpTOCNode>
    </HelpTOC>
    The template.xsl file contains the following:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
      <xsl:template match="/">
        <TREENODES>
           <xsl:for-each select="HelpTOC/HelpTOCNode">
       
              <xsl:element name="TreeNode">
      
                 <xsl:attribute name="Text" ><xsl:value-of select="@Title"/></xsl:attribute>
                 <xsl:attribute name="NavigateURL" ><xsl:value-of select="@Url"/></xsl:attribute>
                 <xsl:attribute name="TARGET" >main</xsl:attribute>               <xsl:for-each select="HelpTOCNode">                  <xsl:element name="TreeNode">
                         <xsl:attribute name="Text" ><xsl:value-of select="@Title"/></xsl:attribute>
                         <xsl:attribute name="NavigateURL" ><xsl:value-of select="@Url"/></xsl:attribute>
                         <xsl:attribute name="Target" >main</xsl:attribute>
                      </xsl:element>               </xsl:for-each>
      
               </xsl:element>
            </xsl:for-each>
         </TREENODES>
      </xsl:template>
    </xsl:stylesheet>
    The XSL transforms the source XML into the correct format for the TreeView.Warning  The TREENODES and TREENODETYPES elements in a data binding source document must be uppercase for the TreeView data binding to work.
      

  4.   

    http://www.gotdotnet.com/team/webcontrols/treeview/tree2.aspxhttp://www.gotdotnet.com/team/webcontrols/treeview/tree.aspx
    还有这个
    http://www.freevbcode.com/ShowCode.asp?ID=652HOWTO: Populate a Treeview Control with an XML Filehttp://support.microsoft.com/default.aspx?scid=kb;EN-US;q244954
    http://msdn.microsoft.com/workshop/webcontrols/behaviors/library/treeview/treeview.asphttp://dev.csdn.net/article/28/28499.shtm
    http://dev.csdn.net/article/28/28502.shtmhttp://aspnet.4guysfromrolla.com/articles/051403-1.aspx
      

  5.   

    Treeview1.TreeNodeSrc=@"C:/Inetpub/wwwroot/ICBC_FJ/files/menu.xml"路径应该用相对路径