首页 > 代码库 > TreeView绑定XmlDataSource

TreeView绑定XmlDataSource

  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <movies>  
  3.   <category id="category1" text="Action">  
  4.     <movie id="movie1" text="Star Wars" />  
  5.     <movie id="movie2" text="Independence Day"/>  
  6.       
  7.   </category>  
  8.   <category id="category2" text="Horror">  
  9.     <movie id="movie3" text="Jaws"/>  
  10.     <movie id="movie4" text="Nightmare Before Christmas"/>  
  11.   </category>  
  12. </movies>  

 

 

  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <script runat="server">  
  5.   
  6. </script>  
  7. <html xmlns="http://www.w3.org/1999/xhtml">  
  8. <head runat="server">  
  9.     <title></title>  
  10. </head>  
  11. <body>  
  12.     <form id="form1" runat="server">  
  13.     <div>  
  14.         <asp:TreeView ID="TreeView1" runat="server" DataSourceID="srcMovies">  
  15.             <DataBindings>  
  16.                 <asp:TreeNodeBinding DataMember="category" TextField="text" ValueField="id" />  
  17.                 <asp:TreeNodeBinding DataMember="movie" TextField="text" ValueField="id" />  
  18.             </DataBindings>  
  19.         </asp:TreeView>  
  20.     </div>  
  21.     <asp:XmlDataSource ID="srcMovies" runat="server" DataFile="~/MoviesComplex.xml">  
  22.     </asp:XmlDataSource>  
  23.     </form>  
  24. </body>  
  25. </html>