TreeView DataBindings
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>TreeView DataBindings</title> </head> <body> <form id="form1" runat="server"> <div id="container"> <asp:TreeView ID="treeMain" runat="server" CssClass="tree" DataSourceID="xmlSource" ShowCheckBoxes="Leaf" MaxDataBindDepth="1" NodeIndent="18"> <DataBindings> <asp:TreeNodeBinding DataMember="Category" TextField="Name" ImageUrlField="Icon" /> <asp:TreeNodeBinding DataMember="Book" TextField="Title" /> </DataBindings> <RootNodeStyle HorizontalPadding="4" /> </asp:TreeView> <asp:XmlDataSource id="xmlSource" runat="server" DataFile="Data.xml" XPath="/Books/Category"/> </div> </form> </body> </html> File: Data.xml <?xml version="1.0" encoding="utf-8" ?> <Books> <Category Name="Internet" Icon="images/small_iconInternet.gif"> <Book Title="E-Business"> <Url>browse.aspx?cat=101</Url> </Book> <Book Title="Servers"> <Url>browse.aspx?cat=102</Url> </Book> <Book Title="Usability"> <Url>browse.aspx?cat=103</Url> </Book> </Category> <Category Name="Networking" Icon="images/small_iconNetworking.gif"> <Book Title="Protocols"> <Url>browse.aspx?cat=201</Url> </Book> <Book Title="Security"> <Url>browse.aspx?cat=202</Url> </Book> </Category> </Books>