This section contains two code examples. The first code example demonstrates how to use an XmlDataSource control with a TreeView control to display XML data from the sample XML file. The second example demonstrates how to use an XmlDataSource control with a templated Repeater control to display XML data.
The following code example demonstrates how to use an XmlDataSource control with a TreeView control to display XML data. The XmlDataSource loads XML data from the XML file identified by the DataFile property.
Visual Basic
<%@ Page Language="VB" %>
ASP.NET Example
C#
<%@ Page Language="C#" %>
ASP.NET Example
J#
<%@ Page Language="VJ#" %>
ASP.NET Example
The XML file in the code example has the following data:
The following code example demonstrates how to use an XmlDataSource control with a templated Repeater control to display XML data. The Repeater control uses an XPath data-binding expression to bind to data items within the XML document that the XmlDataSource represents. For more information about XPath and XPathSelect data-binding syntax, see the XPathBinder class.
Visual Basic
<%@ Page Language="VB" %>
Order
C#
<%@ Page Language="C#" %>
Order
J#
<%@ Page Language="VJ#" %>
Order
Order
| Customer |
<%#XPath("customer/@id")%> |
<%#XPath("customername/firstn")%> |
<%#XPath("customername/lastn")%> |
| Ship To |
<%#XPath("shipaddress/address1")%> |
<%#XPath("shipaddress/city")%> |
<%#XPath("shipaddress/state")%>,
<%#XPath("shipaddress/zip")%> |
Order Summary
<%#XPath("@dept")%> -
<%#XPath(".")%>
The XML file in the code example has the following data:
John
Smith
1234 Tenth Avenue
Bellevue
Washington
98001
- screwdriver
- hammer
- fixture