The Items collection of the RadToolBar object exposes the the root items of a RadToolBar. The child buttons of a dropdown or split button can be accessed using the Buttons collections of these items.
This example demonstrates the server-side creation of the three types of toolbar items described above.
You can create a root RadToolBarButton by using the code below:
C#:
RadToolBarButton rootButton = new RadToolBarButton("Bold"); RadToolBar1.Items.Add(rootButton);
VB:
Dim rootButton as RadToolBarButton = new RadToolBarButton("Bold") RadToolBar1.Items.Add(rootButton)
You can create a RadToolBarDropDown and add a checkable RadToolBarButtonto it by using the code below:
RadToolBarDropDown dropDown = new RadToolBarDropDown("Align"); RadToolBar1.Items.Add(dropDown); RadToolBarButton leftButton = new RadToolBarButton("Left", true, "AlignGroup"); dropDown.Buttons.Add(leftButton);
Dim dropDown as RadToolBarDropDown = new RadToolBarDropDown("Align") RadToolBar1.Items.Add(dropDown) Dim leftButton as RadToolBarButton = new RadToolBarButton("Left", true, "AlignGroup") dropDown.Buttons.Add(leftButton)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.ToolBar.ServerSide.AddRemoveDisable.DefaultCS" %><%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %><%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %><%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %><%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <qsf:HeadTag runat="server" ID="Headtag1" /></head><body class="BODY"> <form runat="server" id="mainForm" method="post"> <telerik:RadScriptManager ID="ScriptManager" runat="server" /> <qsf:Header runat="server" ID="Header1" NavigationLanguage="C#" /> <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Expanded="true"> <div style="height: 180px;"> <div style="clear: both; padding-top: 10px; margin: 0;"> <fieldset style="clear: both; padding-bottom: 10px; padding-left: 10px; width: 500px;"> <legend>Add new button</legend> <asp:Label ID="lblError" runat="server" Style="color: Red;" /> <br /> Target: <asp:DropDownList ID="ddlTarget" runat="server"> <asp:ListItem Text="ToolBar" /> <asp:ListItem Text="Last DropDown" /> <asp:ListItem Text="Last SplitButton" /> </asp:DropDownList> Checked state: <asp:CheckBox runat="server" ID="cbChecked" /> <asp:Button ID="btnAddButton" runat="server" CssClass="qsfButtonBigger" OnClick="btnAddButton_Click" Text="Add" /> </fieldset> <fieldset style="float: left; margin-top: 20px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px;"> <legend>Add other items</legend> <asp:Button ID="btnAddDropDown" runat="server" CssClass="qsfButtonBigger" OnClick="btnAddDropDown_Click" Text="Add new DropDown" /> <asp:Button ID="btnAddSplitButton" runat="server" CssClass="qsfButtonBigger" OnClick="btnAddSplitButton_Click" Text="Add new SplitButton" /> <br /> <br /> </fieldset> <fieldset style="float: left; margin-top: 20px; margin-left: 3px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px;"> <legend>Remove</legend> <asp:Button ID="btnRemoveLastItem" runat="server" CssClass="qsfButtonBigger" OnClick="btnRemoveLastItem_Click" Text="Remove last toolbar item" /><br /> <br /> </fieldset> <fieldset style="float: left; margin-top: 20px; margin-left: 3px; padding-left: 5px; padding-bottom: 5px; padding-right: 5px;"> <legend>Enable/Disable</legend> <asp:Button ID="btnEnableLastItem" runat="server" CssClass="qsfButtonBigger" OnClick="btnEnableLastItem_Click" Text="Enable last toolbar item" /><br /> <br /> <asp:Button ID="btnDisableLastItem" runat="server" CssClass="qsfButtonBigger" OnClick="btnDisableLastItem_Click" Text="Disable last toolbar item" /><br /> <br /> </fieldset> </div> </div> </qsf:ConfiguratorPanel> <telerik:RadToolBar runat="server" ID="RadToolBar1" EnableRoundedCorners="true" EnableShadows="true" /> <qsf:Footer runat="server" ID="Footer1" /> </form></body></html>
Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.
Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.
If you have any questions, do not hesitate to contact us at sales@telerik.com.