Mega Code Archive

 
Categories / ASP.Net / XML
 

Bind inline XML datasource to asp treeview

<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>Using Inline XML Data in an XmlDataSource Control</title> </head> <body>         <form id="form1" runat="server">     <div>         <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1">             <DataBindings>                 <asp:TreeNodeBinding ImageUrl="openbook.gif" TextField="Title" DataMember="book"></asp:TreeNodeBinding>                 <asp:TreeNodeBinding ImageUrl="notepad.gif" TextField="name" DataMember="chapter"></asp:TreeNodeBinding>             </DataBindings>         </asp:TreeView>         </div>         <div>             <asp:XmlDataSource ID="XmlDataSource1" Runat="server" XPath="bookstore/book">                 <Data>                                         <bookstore>                         <book Title="title 1" Price="19.99">                             <chapter num="1" name="Introduction">                                 A                             </chapter>                             <chapter num="2" name="Body">                                 B                             </chapter>                             <chapter num="3" name="Conclusion">                                 C                             </chapter>                         </book>                         <book Title="title 2" Price="24.95">                             <chapter num="1" name="Introduction">                                 D                             </chapter>                             <chapter num="2" name="Body">                                 E                             </chapter>                             <chapter num="3" name="Conclusion">                                 F                             </chapter>                         </book>                        </bookstore>                 </Data>             </asp:XmlDataSource>         </div>     </form> </html>