Mega Code Archive

 
Categories / ASP.Net / Asp Control
 

Binding a TreeView control to the Data xml file

<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Latest Hardware</title> </head> <body>     <form id="form1" runat="server">         <asp:TreeView ID="Treeview1" Runat="server" DataSourceID="Xmldatasource1">             <DataBindings>                 <asp:TreeNodeBinding DataMember="Hardware"                  Text="Computer Hardware" />                 <asp:TreeNodeBinding DataMember="Item" TextField="Category" />                 <asp:TreeNodeBinding DataMember="Option" TextField="Choice" />             </DataBindings>         </asp:TreeView>         <asp:XmlDataSource ID="Xmldatasource1" Runat="server"           DataFile="Data.xml">         </asp:XmlDataSource>     </form> </body> </html> File: Data.xml <?xml version="1.0" encoding="utf-8"?> <Hardware>   <Item Category="A">     <Option Choice="A1" />     <Option Choice="A2" />   </Item>   <Item Category="B">     <Option Choice="B1" />     <Option Choice="B2" />     <Option Choice="B3" />   </Item> </Hardware>