TreeView DataBindings : TreeView « Asp Control « ASP.Net






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>

 








Related examples in the same category

1.A basic TreeView control
2.A TreeView control with the MSDN style applied to it
3.Binding a TreeView control to the Data.xml file
4.Add check boxes to leaf nodes (C#)
5.Add check boxes to leaf nodes (VB)
6.Applying custom images to the TreeView control
7.Expanding and collapsing the nodes of the TreeView control programmatically (C#)
8.Expanding and collapsing the nodes of the TreeView control programmatically (VB)
9.Expanding specific nodes programmatically
10.Expanding nodes programmatically using the Expanded property
11.Displaying database data with a TreeView control.
12.Using Populate On Demand and AJAX
13.Formatting the TreeView Control
14.Using Styles with the TreeView control.
15.Applying styles to different TreeView node levels.
16.Adding nodes programmatically to the TreeView control (C#)
17.Adding nodes programmatically to the TreeView control (VB)
18.Custom TreeView Control
19.Database tree
20.TreeView Populate On Demand
21.Test TreeView
22.Dynamic tree view
23.ParentNodeStyle in a TreeView
24.DirectoryInfo TreeView