Load XML data to tree view : TreeView « XML « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:XmlDataSource ID="sourceDVD" 
                        runat="server" 
                        DataFile="~/Data.xml"/>
        <asp:TreeView ID="TreeView1" 
                      runat="server" 
                      DataSourceID="sourceDVD"
                      AutoGenerateDataBindings="False">
             <DataBindings>
                 <asp:TreeNodeBinding DataMember="DvdList" Text="Root" Value="Root" />
                 <asp:TreeNodeBinding DataMember="DVD" TextField="ID"  />
                 <asp:TreeNodeBinding DataMember="Title" TextField="#InnerText" />
             </DataBindings>
        </asp:TreeView>
    </div>
    </form>
</body>
</html>

File: Data.xml

<?xml version="1.0"?>
<DvdList>
   <DVD ID="1" Category="Category 1">
      <Title>title 1</Title>
      <Director>directory 2</Director>
      <Price>1</Price>
      <Starring>
         <Star>star 1</Star>
         <Star>star 2</Star>
      </Starring>
   </DVD>
   <DVD ID="2" Category="Category 2">
      <Title>title 2</Title>
      <Director>directory 2</Director>
      <Price>2</Price>
      <Starring>
         <Star>star 3</Star>
         <Star>star 4</Star>
      </Starring>
   </DVD>
</DvdList>








25.6.TreeView
25.6.1.Load XML data to tree view