ASP.NET Tutorial/XML/TreeView — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:57, 26 мая 2010

Load XML data to tree view

<%@ 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>