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

Cant add an item into RadListBox

4 Answers 136 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
KobusVisagie
Top achievements
Rank 1
KobusVisagie asked on 01 Dec 2011, 08:23 AM
Hi Everone

Can some one tell me why i get this error
Microsoft JScript runtime error: Object doesn't support property or method 'get_items'

when i execute the following js code
var listbox = document.getElementById("<%=rlbCustomEmails.ClientID %>");
var item = new Telerik.Web.UI.RadListBoxItem();
item.set_text(email);
listbox.get_items().add(item); //I get the error here

it is searching for this control
<telerik:radlistbox runat="server" style="position: absolute; top: 290px; left: 400px;"
        height="240px" width="255px" ID="rlbCustomEmails"></telerik:radlistbox>

4 Answers, 1 is accepted

Sort by
0
KobusVisagie
Top achievements
Rank 1
answered on 01 Dec 2011, 09:44 AM
ok so i found my mistake, i should have used $find instead of document.getelementbyid
but i do get the following exception when it hits items.add(email);
it says Microsoft JScript runtime error: Object doesn't support property or method 'get_parent', im guessing i'm doing something wrong, but here is my code below
var listbox = $find("<%= RadListBox1.ClientID %>");
                    var items = listbox.get_items();
                    listbox.trackChanges();
                    var item = new Telerik.Web.UI.RadListBoxItem();
                    item.set_text(email);
                    items.add(email); //it fails here
                    listbox.commitChanges();

it seems the error comes from here

Telerik.Web.UI.ControlItem.registerClass("Telerik.Web.UI.ControlItem");
Type.registerNamespace("Telerik.Web.UI");
Telerik.Web.UI.ControlItemCollection=function(a){this._array=new Array();
this._parent=a;
this._control=null;
};
Telerik.Web.UI.ControlItemCollection.prototype={add:function(b){var a=this._array.length;
this.insert(a,b);
},insert:function(b,c){var a=c.get_parent(); //Error comes from here
var d=this._parent._getControl();
if(a){a._getChildren().remove(c);
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Dec 2011, 10:17 AM
Hello Gregory,

Here is the sample code that I tried which worked as expected.
JS:
function AddItem()
{
    var listbox = $find("<%= RadListBox1.ClientID %>");
    var item = new Telerik.Web.UI.RadListBoxItem();
    item.set_text("Mario");
    listbox.trackChanges();
    listbox.get_items().add(item);
    item.select();
    listbox.commitChanges();
}

Also check the following help documentation which explains client objects of RadListBox.
RadListBox client API

-Princy.
0
KobusVisagie
Top achievements
Rank 1
answered on 01 Dec 2011, 10:35 AM
Thank you for the reply, i did get that right, but there is the other problem im stuck with now, ive sent it as a reply below my first problem

Greg
0
KobusVisagie
Top achievements
Rank 1
answered on 01 Dec 2011, 11:03 AM
ok so i rewrote the code to what you have given, and it looks like it is working, thank you

Regards
Greg
Tags
ListBox
Asked by
KobusVisagie
Top achievements
Rank 1
Answers by
KobusVisagie
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or