Hi,
Here is an example of how to access the dropdown items via the FindDropDownByValue method:
ASPX
<telerik:RadToolBar ID="RadToolBar1" runat="server">
<Items>
<telerik:RadToolBarButton runat="server" Text="Button 0" Value="button1">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton runat="server" Text="Button 1">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton runat="server" Text="Button 2">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton runat="server" Text="Button 3">
</telerik:RadToolBarButton>
<telerik:RadToolBarDropDown runat="server" Text="DropDown 0" Value="MyDropDown">
<Buttons>
<telerik:RadToolBarButton runat="server" Text="Child Button 1" Value="value1">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton runat="server" Text="Child Button 2" Value="value2">
</telerik:RadToolBarButton>
<telerik:RadToolBarButton runat="server" Text="Child Button 3" Value="value3">
</telerik:RadToolBarButton>
</Buttons>
</telerik:RadToolBarDropDown>
</Items>
</telerik:RadToolBar>
C#
protected void Page_Load(object sender, EventArgs e)
{
var dropdown1 = RadToolBar1.FindItemByValue("MyDropDown") as RadToolBarDropDown;
dropdown1.Buttons[0].Text = "Changed button";
var dropdown2 = RadToolBar1.FindDropDownByValue("MyDropDown");
dropdown2.Buttons.FindItemByValue("value2").Text = "Changed button text from FindDropDownByValue";
var dropdown3 = RadToolBar1.Items.FindItemByValue("MyDropDown") as RadToolBarDropDown;
dropdown3.Buttons.FindItemByValue("value3").Text = "Changed button text from Items.FindItemByValue ";
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim dropdown1 = TryCast(RadToolBar1.FindItemByValue("MyDropDown"), RadToolBarDropDown)
dropdown1.Buttons(0).Text = "Changed button"
Dim dropdown2 = RadToolBar1.FindDropDownByValue("MyDropDown")
dropdown2.Buttons.FindItemByValue("value2").Text = "Changed button text from FindDropDownByValue"
Dim dropdown3 = TryCast(RadToolBar1.Items.FindItemByValue("MyDropDown"), RadToolBarDropDown)
dropdown3.Buttons.FindItemByValue("value3").Text = "Changed button text from Items.FindItemByValue "
End Sub
Regards,
Rumen
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hello,
In most cases, the value is used to access a ToolBar item. If the Value of the RadToolBarDropDown is set by the selected button's value, it will not be a reliable way to identify a dropdown item.
That is why, for obtaining a RadToolBarDropDown item, you can use the Attributes collection of the server-side item object. Here is a simple example of how to do that. Note that you can add them either in the markup or from the code-behind. The runat=server for the item markup is not necessary, it will still work but Visual Studio might underline it as a warning.
<telerik:RadToolBar runat="server" ID="RadToolbar1">
<Items>
<telerik:RadToolBarDropDown data-id="my-dropdown-item">
<Buttons>
<telerik:RadToolBarButton Text="Button markup"></telerik:RadToolBarButton>
</Buttons>
</telerik:RadToolBarDropDown>
</Items>
</telerik:RadToolBar>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var ddl = RadToolbar1.FindItem(x => x.Attributes["data-id"] == "my-dropdown-item") as RadToolBarDropDown;
ddl.Buttons.Add(new RadToolBarButton("Button code behind"));
}
}
FindItemByAttribute can be easily implemented as an extension method until it is built-in:
public static class TelerikToolBarExtensions{
public static RadToolBarItem FindItemByAttribute(this RadToolBar toolbar, string attribute, string value)
{
return toolbar.FindItem(x => x.Attributes["data-id"] == "my-dropdown-item");
}
}
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//var ddl = RadToolbar1.FindItem(x => x.Attributes["data-id"] == "my-dropdown-item") as RadToolBarDropDown;
var ddl = RadToolbar1.FindItemByAttribute("data-id","my-dropdown-item") as RadToolBarDropDown;
ddl.Buttons.Add(new RadToolBarButton("Button code behind"));
}
}
}
Regards,
Peter Milchev
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.