Partager via


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>

Remarks

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.

Example

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

<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>
<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>

See Also

Reference

XmlDataSource

Other Resources

XmlDataSource Web Server Control