RadControls for ASP.NET AJAX
Using the server-side API, you can programmatically add, remove, disable, or select items in RadToolBar.
Adding items
Use the Add method of the RadToolBarItemCollection object to add items programmatically. To add buttons to the RadToolBarDropDown or RadToolBarSplitButton, use the Buttons collections of these objects as shown below:
CopyC#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
RadToolBarButton button = new RadToolBarButton();
button.Text = "Button1";
button.Value = "1";
RadToolBar1.Items.Add(button);
RadToolBarDropDown dropDown = new RadToolBarDropDown();
dropDown.Text = "DropDown1";
dropDown.Buttons.Add(new RadToolBarButton("Child Button1"));
RadToolBar1.Items.Add(dropDown);
RadToolBarSplitButton splitButton = new RadToolBarSplitButton();
splitButton.Text = "SplitButton1"; splitButton.Value = "1";
splitButton.Buttons.Add(new RadToolBarButton("Child Button1"));
RadToolBar1.Items.Add(splitButton);
}
}
CopyVB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
Dim button As New RadToolBarButton()
button.Text = "Button1"
button.Value = "1"
RadToolBar1.Items.Add(button)
Dim dropDown As New RadToolBarDropDown()
dropDown.Text = "DropDown1"
dropDown.Buttons.Add(New RadToolBarButton("Child Button1"))
RadToolBar1.Items.Add(dropDown)
Dim splitButton As New RadToolBarSplitButton()
splitButton.Text = "SplitButton1"
splitButton.Value = "1"
splitButton.Buttons.Add(New RadToolBarButton("Child Button1"))
RadToolBar1.Items.Add(splitButton)
End If
End Sub
Removing items
Use the Remove method of the RadToolBarItemCollection or the Buttons collections of the RadToolBarDropDown or the RadToolBarSplitButton objects to remove items:
CopyC#
RadToolBarItem itemToRemove = RadToolBar1.FindItemByText("Button1");
RadToolBar1.Items.Remove(itemToRemove);
splitButton.Buttons.Remove(childButton);
dropDown.Buttons.Remove(childButton);
CopyVB.NET
Dim itemToRemove As RadToolBarItem = RadToolBar1.FindItemByText("Button1")
RadToolBar1.Items.Remove(itemToRemove)
splitButton.Buttons.Remove(childButton)
dropDown.Buttons.Remove(childButton)
Disabling items
Use the Enable property of the RadToolBarItem object to enable or disable an item:
CopyC#
RadToolBarItem itemToDisable = RadToolBar1.FindItemByText("Button1");
itemToDisable.Enabled = false;
CopyVB.NET
Dim itemToDisable As RadToolBarItem = RadToolBar1.FindItemByText("Button1")
itemToDisable.Enabled = False
See Also