Cant add an item into RadListBox

5 posts, 1 answers
  1. KobusVisagie
    KobusVisagie avatar
    47 posts
    Member since:
    Sep 2010

    Posted 01 Dec 2011 Link to this post

    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>

  2. KobusVisagie
    KobusVisagie avatar
    47 posts
    Member since:
    Sep 2010

    Posted 01 Dec 2011 Link to this post

    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);
  3. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Dec 2011 Link to this post

    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.
  4. KobusVisagie
    KobusVisagie avatar
    47 posts
    Member since:
    Sep 2010

    Posted 01 Dec 2011 Link to this post

    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
  5. KobusVisagie
    KobusVisagie avatar
    47 posts
    Member since:
    Sep 2010

    Posted 01 Dec 2011 Link to this post

    ok so i rewrote the code to what you have given, and it looks like it is working, thank you

    Regards
    Greg
Back to Top