here below is the code
Expand|Select|Wrap|Line Numbers
- <asp:XmlDataSource ID="XmlDataSource1" runat="server"
- DataFile="~/App_Data/treedata.xml" XPath="\treedata"
- TransformFile="~/App_Data/xslfile.xslt"></asp:XmlDataSource>
- <asp:TreeView ID="PageTreeView" runat="server" DataSourceID="XmlDataSource1"
- ExpandDepth="5" onselectednodechanged="TreeView1_SelectedNodeChanged"
- ShowLines="True">
- <DataBindings>
- <asp:TreeNodeBinding DataMember="genre" TextField="name" />
- <asp:TreeNodeBinding DataMember="book" TextField="title" />
- <asp:TreeNodeBinding DataMember="title" FormatString="ISBN: {0}" TextField="ISBN" />
- <asp:TreeNodeBinding DataMember="price" FormatString="${0}" TextField="#InnerText" />
- <asp:TreeNodeBinding DataMember="comments" Text="Comments" Value="Comments" />
- <asp:TreeNodeBinding DataMember="userComment" TextField="#InnerText" ToolTipField="rating" />
- </DataBindings>
- </asp:TreeView>
now below is the xml file names "treedata.xml"
Expand|Select|Wrap|Line Numbers
- <bookstore>
- <genre name="fiction">
- <book ISBN="10-000000-001" title="The Iliad and The Odyssey">
- <title ISBN="10-000000-001">The Iliad and The Odyssey</title>
- <price>12.95</price>
- <comments>
- <userComment rating="4">Best translation I've read.</userComment>
- <userComment rating="2">I like other versions better.</userComment>
- </comments>
- </book>
- <book ISBN="10-000000-999" title="Anthology of World Literature">
- <title ISBN="10-000000-999">Anthology of World Literature</title>
- <price>24.95</price>
- <comments>
- <userComment rating="3">Needs more modern literature.</userComment>
- <userComment rating="4">Excellent overview of world literature.</userComment>
- </comments>
- </book>
- </genre>
- <genre name="nonfiction">
- <book ISBN="11-000000-002" title="Computer Dictionary">
- <title ISBN="11-000000-002">Computer Dictionary</title>
- <price>24.95</price>
- <comments>
- <userComment rating="3">A valuable resource.</userComment>
- </comments>
- </book>
- <book ISBN="11-000000-003" title="Cooking on a Budget">
- <title ISBN="11-000000-003">Cooking on a Budget</title>
- <price>23.95</price>
- <comments>
- <userComment rating="4">Delicious!</userComment>
- </comments>
- </book>
- </genre>
- </bookstore>
Expand|Select|Wrap|Line Numbers
- protected void Page_Load(object sender, EventArgs e)
- {
- XmlDataSource1.XPath = "treedata.xml";
- PageTreeView.DataBind();
- }