Version

Binding to an XML Data Source

Before You Begin

The WebExplorerBar™ can bind to a hierarchical data source, displaying each level of the data hierarchy. The topmost level represents the different groupings, with each child level representing the items.

What You Will Accomplish

You will learn how to bind to data using the WebExplorerBar control and an XmlDataSource component. The sample uses the CategoriesandProducts file.

Follow These Steps

  1. Drag a ScriptManager component from the Visual Studio™ Toolbox onto the web page.

  2. Drag a WebExplorerBar control onto the page.

  3. Drag an XmlDataSource component onto the page.

  4. Set up the XmlDataSource component to retrieve data using an XML file.

    1. Set the DataFile property to the location of the data file.

    2. Set the XPath property to select the Category nodes.

In HTML:

<asp:XmlDataSource
        ID="XmlDataSource1"
        runat="server"
        DataFile="~/App_Data/CategoriesAndProducts.xml"
        XPath="Categories/Category">
</asp:XmlDataSource>
  1. Set WebExplorerBar’s DataSourceID property to XmlDataSource1, the id of the XmlDataSource component.

  2. Set the data bindings to display the CategoryName and ProductName attributes from the Category and Product nodes, respectively.

    1. Create a ExplorerBarItemBinding object and set its DataMember property to "Category".

    2. Set the TextField property to "CategoryName".

    3. Create a second ExplorerBarItemBinding object and set its DataMember property to "Product".

    4. Set the TextField property to "ProductName".

In HTML:

<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="300px" DataSourceID="XmlDataSource1" BehaveMode="AnyExpandable">
    <DataBindings>
        <ig:WebExplorerBinding DataMember="Category" TextField="CategoryName" />
        <ig:WebExplorerBinding DataMember="Product" TextField="ProductName" />
    </DataBindings>
</ig:WebExplorerBar>
  1. Run the application. The WebExplorerBar control displays the data from the Category and Product nodes.

WebExplorerBar BindingtoanXmlDatatSource 01.png