Search code examples
asp.netteleriktelerik-combobox

Weird behavior while creation of two Telerik RadComboBox items programmatically


I've two Telerik RadComboBox controls, while adding of their items using the following code

foreach (var gate in Enum.GetNames(typeof(AuthorizedGates)))
{
     var item = new RadComboBoxItem(gate, Convert.ToString((int)Enum.Parse(typeof(AuthorizedGates), gate)));
     ddlTelerik1.Items.Add(item);
     ddlTelerik2.Items.Add(item);
 }

at runtime, the first combobox has zero items i.e. items are not added to it while items are added to the second one!

I tried the same for ASP.NET DropDownList using the following code

foreach (var gate in Enum.GetNames(typeof(AuthorizedGates)))
{
    var item = new ListItem(gate, Convert.ToString((int)Enum.Parse(typeof(AuthorizedGates), gate)));
    ddlAspNet1.Items.Add(item);
    ddlAspNet2.Items.Add(item);
}

it is working properly and items got added to both of them.

Any ideas what could be the reason behind this weird behavior?


Solution

  • The difference is that the RadComboBox item is a control like the RadComboBox or DropDownList controls, so it's a class that indirectly inherits from WebControl, and can only have one instance on the page. It's not like a ListItem (which inherits from Object).