RadToolBar for ASP.NET AJAX

RadControls for ASP.NET AJAX

RadToolBar supports binding to all ASP.NET 2.0 DataSource components, including

  • AccessDataSource
  • SqlDataSource
  • XmlDataSource
  • ObjectDataSource
  • SiteMapDataSource
  • LinqDataSource

To bind to a DataSource component, all you need to do is set the DataSourceID property of the toolbar to the ID of the DataSource component. You should also set the DataTextField and DataValueField properties of the toolbar to map the Text and Value properties of the buttons to the respective columns/fields from the data source.

If you need to map additional columns from the data source to properties of the toolbar buttons, you can use the ButtonDataBound event. The event arguments passed to the event, e.Button and e.Button.DataItem, hold the instance of the toolbar button being bound and the DataItem to which it is bound. You can map a property from the DataItem to the corresponding property of the toolbar button. Be sure to cast the DataItem object to the proper data type first.

Table-based DataSource components, such as SqlDataSource and AccessDataSource can be used to bind the toolbar declaratively in design time.

AccessDataSource

CopyASPX
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Data/ToolBar.mdb"
    SelectCommand="SELECT * FROM [Tools]"></asp:AccessDataSource>
<telerik:RadToolBar ID="RadToolBar1" runat="server" DataTextField="Text" DataValueField="Value"
    DataSourceID="AccessDataSource1" OnItemDataBound="RadToolBar1_ButtonDataBound" />

SqlDataSource

CopyASPX
<telerik:RadToolBar runat="server" ID="RadToolBar1" DataSourceID="SqlDataSource1"
    DataTextField="TargetName" DataValueField="TargetValue" OnTabDataBound="RadToolBar1_ButtonDataBound">
</telerik:RadToolBar>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="Persist Security Info=False;Integrated Security=true;Initial Catalog=MyDB;server=(local)"
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT TargetName, TargetValue from ToolBarTable" />

XmlDataSource

CopyASPX
<telerik:RadToolBar ID="RadToolBar1" runat="server" DataSourceID="XmlDataSource1"
    Orientation="Horizontal" DataTextField="Text" DataValueField="Value">
    <CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadToolBar>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/Buttons.xml" XPath="Items/Item">
</asp:XmlDataSource>
CopyXML
<?xml version="1.0" encoding="utf-8" ?>
<items>
     <Item Text="Add One" Value="1" /> 
     <Item Text="Add Two" Value="2" /> 
     <Item Text="Add Three" Value="3" />
</items>

ObjectDataSource

You can bind RadToolBar to an object-based data source such as ObjectDataSource or any class that implements the IEnumerable interface.

When using ObjectDataSource, you can bind RadToolBar declaratively at design time. The SelectMethod of the ObjectDataSource should return an object that supports the IEnumerable or ICollection interface. Such collections include Array, ArrayList, and List<type>.

If the SelectMethod returns a collection of strings, those strings are automatically mapped to the Text property of the respective buttons. If the collection contains objects (as opposed to string values), you can use the DataTextField and the DataValueField properties to map a property from the object directly to the Text and Value properties of the button.

To map additional properties from the object to other properties of the respective button, use a ButtonDataBound event handler. The event arguments passed to the event, e.Buttonand e.Button.DataItem, hold the instance of the button being bound and the DataItem associated with the button. You can map a property from the DataItem to the property of the RadToolBarButton class (make sure to cast the DataItem object to your respective data type first).

The following example shows a RadToolBar bound declaratively to an ObjectDataSource:

CopyASPX
<telerik:RadToolBar ID="RadToolBar1" runat="server" DataSourceID="ObjectDataSource1">
</telerik:RadToolBar>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetButtons"
    TypeName="ButtonsArray"></asp:ObjectDataSource>

The ObjectDataSource component is configured to use the following class definition:

See Also