当使用Treeview控件绑定Sitemap文件时,首先引入SiteMapDataSource,但是不用显示指点它的datasource file,它会自动绑定到Web.sitemap,但是注意这时的Web.sitemap要放在根目录下,否则会出现类似XmlDataSource找不到Web.sitemap的错误。
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
        </asp:TreeView>
    </div>
    </form>
</body>
</html>

////Web.sitemap
<?xml version="1.0" endoding="utf-8" ?>
<siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0 >
   <siteMapNode url="" title="home" description="">
      <siteMapNode url="" title="parent" description="" />
      <siteMapNode url="" title="child" description="" />
   </siteMapNode>
</siteMap>

运行结果为
折叠 home home
parent
child