Section 5.6. Bind to an XmlDataSource Control


5.6. Bind to an XmlDataSource Control

You can bind to an XML document just as easily as you bind to a database. An XmlDataSource control loads an XML document and exposes its data.


Note: You can bind a data control to an XML document using the XmlDataSource control.

If the XML document you load is hierarchical, the data is exposed hierarchically; which makes it ideal for mapping an XML document to a treeView control.

5.6.1. What just happened?

To review, in the XML you created an Author element with a Name attribute:

<Author Name = "Jesse Liberty" />

In the TreeView DataBindings Editor you selected Author in the Available DataBindings list and clicked Add, adding it to the Selected DataBindings list. Then you set the TextField property to Name (matching the name of the attribute). Then the TreeView DataBindings Editor emitted HTML into your .aspx file that corresponded to these choices:


Note: Where possible, I've made the tags self-closing to make the HTML easier to read.
<asp:TreeNodeBinding TextField="Name" DataMember="Author" />

Run the application, and the data in the XML document is bound to the control, as shown in Figure 5-26.

Figure 5-26. XML bound data


5.6.2. What about...

...if I want a different look and feel for the hierarchy?

Try a different auto format, such as the XP File Explorer format. As shown in Figure 5-27, it is easy to change formats to get the look and behavior you want.

Figure 5-27. Changing the file format


5.6.3. Where can I learn more?

To learn more about the XmlDataSource control, see the article "Data Access in ASP.NET 2.0" in the MSDN Library.



Visual C# 2005(c) A Developer's Notebook
Visual C# 2005: A Developers Notebook
ISBN: 059600799X
EAN: 2147483647
Year: 2006
Pages: 95
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net