ASP.NET Tutorial/Data Binding/TreeNodeBinding

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

Using TreeNodeBinding

<%@ 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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TreeView ID="_bookstoreTreeView" runat="server" DataSourceID="_bookstoreDataSource1" ShowLines="True">
            <DataBindings>
                <asp:TreeNodeBinding DataMember="book" ImageUrl="~/img/closedbook.gif" TextField="Title" />
                <asp:TreeNodeBinding DataMember="chapter" ImageUrl="~/img/notepad.gif" TextField="name" />
                <asp:TreeNodeBinding DataMember="genre" ImageUrl="~/img/folder.gif" Text="." TextField="name" />
            </DataBindings>
        </asp:TreeView>
        <asp:XmlDataSource ID="_bookstoreDataSource1" runat="server" DataFile="~/App_Data/Bookstore.xml">
        </asp:XmlDataSource>
        <br />
        
    </div>
    </form>
</body>
</html>
File: Bookstore.xml
<Bookstore>
  <genre name="Business">
    <book ISBN="1" Title="Database" Price="19.99">
      <chapter num="1" name="Introduction">
        Abstract...
      </chapter>
      <chapter num="2" name="Body">
        Abstract...
      </chapter>
      <chapter num="3" name="Conclusion">
        Abstract...
      </chapter>
    </book>
    <book ISBN="2" Title="Computer" Price="2.99">
      <chapter num="1" name="Introduction">
        Abstract...
      </chapter>
      <chapter num="2" name="Body">
        Abstract...
      </chapter>
      <chapter num="3" name="Conclusion">
        Abstract...
      </chapter>
    </book>
    <book ISBN="3" Title="VB" Price="19.99">
      <chapter num="1" name="Introduction">
        Abstract...
      </chapter>
      <chapter num="2" name="Body">
        Abstract...
      </chapter>
      <chapter num="3" name="Conclusion">
        Abstract...
      </chapter>
    </book>
  </genre>
</Bookstore>