Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
General Reference
ASP.NET Reference
 XmlDataSource Web Server Control De...
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework General Reference
XmlDataSource Web Server Control Declarative Syntax

Represents an XML data source to data-bound controls.

<asp:XmlDataSource
    CacheDuration="string|Infinite"
    CacheExpirationPolicy="Absolute|Sliding"
    CacheKeyDependency="string"
    DataFile="string"
    EnableCaching="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnTransforming="Transforming event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    TransformArgumentList="string"
    TransformFile="string"
    Visible="True|False"
    XPath="string"
>
    <Data>string</Data>
    <Transform>string</Transform>
</asp:XmlDataSource>

The XmlDataSource control is a data source control that represents XML data to data-bound controls. The XmlDataSource control can be used by data-bound controls to display both hierarchical and tabular data. The XmlDataSource control is typically used to display hierarchical XML data in read-only scenarios. Because the XmlDataSource control extends the HierarchicalDataSourceControl class, it works with hierarchical data. The data source control also implements the IDataSource interface and works with tabular, or list-style, data.

For more information on the XmlDataSource control, see XmlDataSource Web Server Control.

The following example demonstrates how to bind the TreeView control to an XmlDataSource control with XML data that is defined using the Data property.

Visual Basic
<asp:TreeView id="BookTreeView" dataSourceID="BookXmlDataSource" runat="server">
<DataBindings>
  <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
  <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
  <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
</DataBindings>
</asp:TreeView>

<asp:XmlDataSource id="BookXmlDataSource" runat="server">
  <Data>
    <Book Title="Book Title">
    <Chapter Heading="Chapter 1">
      <Section Heading="Section 1">
      </Section>
      <Section Heading="Section 2">
      </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
      <Section Heading="Section 1">
      </Section>
    </Chapter>
    </Book>
  </Data>
</asp:XmlDataSource>
C#
<asp:TreeView id="BookTreeView" dataSourceID="BookXmlDataSource" runat="server">
<DataBindings>
  <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
  <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
  <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
</DataBindings>
</asp:TreeView>

<asp:XmlDataSource id="BookXmlDataSource" runat="server">
  <Data>
    <Book Title="Book Title">
    <Chapter Heading="Chapter 1">
      <Section Heading="Section 1">
      </Section>
      <Section Heading="Section 2">
      </Section>
    </Chapter>
    <Chapter Heading="Chapter 2">
      <Section Heading="Section 1">
      </Section>
    </Chapter>
    </Book>
  </Data>
</asp:XmlDataSource>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker