This is a migrated thread and some comments may be shown as answers.

[Solved] Adding Multiple Items Client Side

1 Answer 231 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Brendan
Top achievements
Rank 1
Brendan asked on 19 May 2009, 08:19 PM
I'm trying to populate a RadComboBox on the client side with values from an array. Here's the markup I'm using for the control:

<telerik:RadComboBox ID="cboSerialNumber" runat="server" /> 
 

The rest of the page doesn't matter. It's just in a simple HTML page. Here's the javascript code I'm using to add items:

    function InitDetails() 
    { 
        var combo = $find("<%= cboSerialNumber.ClientID %>"); 
        combo.get_items().clear(); 
         
        for (i = 0; i < arrSerials.length; i++) 
        { 
            AddSerial(arrSerials[i]); 
        } 
    } 
 
    function AddSerial(num) 
    { 
        var combo = $find("<%= cboSerialNumber.ClientID %>"); 
 
        var comboItem = new Telerik.Web.UI.RadComboBoxItem(); 
        comboItem.set_text(num); 
        combo.trackChanges(); 
        combo.get_items().add(comboItem); 
        comboItem.select(); 
        combo.commitChanges();       
    } 

arrSerials contains a list of serials that the user has input through a text box. Each are string values for the serial number.

And here's the issue. The second time through this loop, the AddSerial function throws an exception on the combo.get_items().add(comboItem); line

The error I'm seeing is: Object doesn't support this property or method.
Debugging halts on the bolded line in this function from Telerik:

_removeEmTags:function(text){
var _1b2=text.indexOf("<em>");
var _1b3=text.indexOf("</em>");
if(_1b2>=0&&_1b3>_1b2){
text=String.format("{0}{1}{2}",text.substr(0,_1b2),text.substr(_1b2+4,_1b3-_1b2-4),text.substr(_1b3+5));
}
return text;
}




Is there some other way I'm supposed to be adding a list of items to the combo box on the client side? Can anyone else reproduce this issue?

Thanks for your time,
Bren

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 22 May 2009, 08:41 AM
Hi Brendan,

Please try calling track-/commit- Changes before clearing the Items and after all new Items are added:

function InitDetails()  
{  
    var combo = $find("<%= cboSerialNumber.ClientID %>");  
    combo.trackChanges();  
    combo.get_items().clear();  
      
    for (i = 0; i < arrSerials.length; i++)  
    {  
        AddSerial(arrSerials[i]);  
    }  
     
    combo.commitChanges();  
}  
 
function AddSerial(num)  
{  
    var combo = $find("<%= cboSerialNumber.ClientID %>");  
 
    var comboItem = new Telerik.Web.UI.RadComboBoxItem();  
    comboItem.set_text(num); 
    combo.get_items().add(comboItem);  
    comboItem.select();        
}  

Is the error still appearing after running the code after the changes?

All the best,
Simon
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
Tags
ComboBox
Asked by
Brendan
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or