ComponentOne ToolBar for ASP.NET AJAX: ToolBar for ASP.NET AJAX Task-Based Help > Bind C1ToolBar to an XMLDataSource

Bind C1ToolBar to an XMLDataSource

This lesson shows you how to create an XML file through Visual Studio 2008 installed templates, add the XML Data Source component to the Web site, and assign it to the C1ToolBar, and then set the binding for the C1ToolBar.

To create an XML file, add the XMLDataSource component to the Web site, and then assign it to the C1ToolBar control.

1.   Start a new Web Site project.

2.   Right-click on the App_Data in the Solution Explorer and select Add New Item. The Add New Item dialog box appears.

3.   Select the XML File and rename it ToolBar.xml.

4.   Switch to the XML view and add the following data to the ToolBar.xml:

<?xml version="1.0" encoding="utf-8" ?>

<root>

<c1toolbardropdownlist Text="Advanced">

        <c1toolbarbutton Text="Advanced1"></c1toolbarbutton>

        <c1toolbarbutton Text="Advanced2"></c1toolbarbutton>

        <c1toolbarbutton Text="Advanced3"></c1toolbarbutton>

</c1toolbardropdownlist>

<c1toolbarbutton Text="Automatic Updates"></c1toolbarbutton>

<c1toolbarsplitbutton Text="Remote">

        <c1toolbarbutton Text="Remote1"></c1toolbarbutton>

        <c1toolbarbutton Text="Remote2"></c1toolbarbutton>

</c1toolbarsplitbutton>

<c1toolbarcheckbutton Text="General"></c1toolbarcheckbutton>

<c1toolbarbutton Text="Computer Name"></c1toolbarbutton>

<c1toolbardropdownlist Text="Hardware">

        <c1toolbarbutton Text="Hardware1"></c1toolbarbutton>

        <c1toolbarbutton Text="Hardware2"></c1toolbarbutton>

        <c1toolbarbutton Text="Hardware3"></c1toolbarbutton>

        <c1toolbarbutton Text="Hardware4"></c1toolbarbutton>

  </c1toolbardropdownlist>

</root>

5.   Switch back to the .aspx page and select the Design tab to switch to Design view.

6.   Expand the Data node in the Visual Studio Toolbox and add the XmlDataSource component to the Web site.

7.   Select the XmlDataSource1 from the dropdown listbox in the Properties window.

8.   Click on the ellipsis button next to the DataFile property to open the Select XML File dialog box. Select the App_Data and click on the ToolBar.xml file. Click OK to add it to the XmlDataSource1.DataFile property.

 

 

9.   Set the XmlDataSource1.Xpath to root/*.

10.  Double-click on the C1ToolBar control from the Visual Studio toolbox to add it to your page.

11.  Open the C1ToolBar control's Tasks menu and select XmlDataSource1 from the Choose Data Source dropdown listbox

 

 

12.  Select Edit Bindings from the C1ToolBar Tasks menu.

The Bindings Collection Editor appears for the C1ToolBar control.

13.  Select the dropdown listbox and add the c1toolbardropdownlist, c1toolbarbutton, c1toolbarsplitbutton, and c1toolbarcheckbutton to C1ToolBarItemBindingCollection.

 

 

14.  Set the TextField property to Text for each member and click OK when you are finished to save and close the Bindings Collection Editor.

 

 

Note: Two key properties are the DataMember and TextField. The DataMember sets the data member from the xml file to bind to the C1Toolbar. The TextField gets the value of the Text property of the object to which the C1ToolBarItemBinding object is applied.

This Topic Illustrates the Following:

Run the project and notice the data from the toolbar.xml file is bound to the C1ToolBar control.

 


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.