

Using XPathSelect to Return Selected Nodes For details about the People.xml file used for in the example, see XmlDataSource Web Server Control Overview. The data-binding expression in the template uses the XPath method to return values from the XML data. The following code example shows a DataList control bound to an XmlDataSource control. The string format parameter uses the syntax defined for the Format method of the String class. When using the XPath data-binding method, you pass an XPath query and an optional second parameter to specify a format for the returned string. The XPath data-binding method navigates the XML hierarchy and returns a value from a node or an attribute anywhere in the hierarchy. If you are binding the tabular control to an XmlDataSource control, you can additionally use the XPath method, which enables you to specify an XPath query for read-only data binding. Tabular controls allow you to bind controls in a template to data using the Eval or Bind methods. Binding to the XML Hierarchy using the XPath Method You can also specify an attribute name in an Eval data-binding expression in a control template. As a result, you can specify an attribute name from the first-level node as the name of a DataField for a BoundField object. The XmlDataSource control exposes the attributes of the first-level nodes as the equivalent of columns in a data table.

When you bind a tabular data-bound control to the XmlDataSource control, the control renders only the first level of the XML hierarchy. You can also bind tabular data-bound controls such as a GridView or DataList control to the XmlDataSource control. The XmlDataSource control is used primarily to expose hierarchical XML data to bound controls such as the TreeView or Menu controls.
