Trying to add a value to a RadListBox

4 posts, 0 answers
  1. Kathy
    Kathy avatar
    35 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2010 Link to this post

    I took your sample ListBoxInItemComboTemplate and modified to have the listbox populated with data from a datasource.  That works fine.  I need to add an item "ALL" and what I'm hoping to do is to check if the user selected "ALL" then turn off the other items in the listbox.  Would that be done on the client side? 
    <td><telerik:RadComboBox ID="ObjectiveCombo" Runat="server" 
        DataTextField="ObjectiveName"
        DataValueField="ObjectiveID" Skin="Office2007" Width="487px" 
        OnClientDropDownClosed = "onObjectiveDDClosed" 
            >
             
            <Items><telerik:RadComboBoxItem Text="" />
             </Items>
            <ItemTemplate>
                    <div id="div1">
                        <telerik:RadListBox ID="RadListBox1" runat="server" Width="100%" SelectionMode="Multiple"
                            OnClientSelectedIndexChanged="onSelectedIndexChangedObjective" 
                            DataSourceID="ObjectiveDS" DataTextField="ObjectiveName" 
                            DataValueField="ObjectiveID">
                        </telerik:RadListBox>
                    </div>
                    <script type="text/javascript">
                        var div1 = document.getElementById("div1");
                        div1.onclick = stopPropagation;
                    </script>
                </ItemTemplate>
      
    </telerik:RadComboBox>
    This is what I have.  The listbox is inside an item template.

    Also, I was trying to find out how many items I have selected in my listbox when the dropdown closes.  The get_value() call works but the get_count() gives an error. 
    function onObjectiveDDClosed(sender, eventArgs) {
            var text = "";
            var value = "";
      
            var comboBox = $find("<%= ObjectiveCombo.ClientID %>");
            var items = comboBox.get_items().getItem(0).get_value();
            var num = comboBox.get_items().getItem(0).get_count(); 
            alert(num);
            var total = items.split(",");
            alert(total.length);
              
             
             
        }
    This client-side stuff is a little new for me.  It's frustrating when you know what you want, but you struggle with a new language.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Nov 2010 Link to this post

    Hello Kathy,


    You can access the RadListBox control from client side and iterate through the items to set it as disabled.

    The documentation shows how to access the control in combobox.
    Finding an item in template

    The following client code  will help you in finding the number of items selected in RadListBox.

    Client code:
    <script type="text/javascript">
        function onObjectiveDDClosed(sender, eventArgs) {
            var comboBox = sender;
            var ListBox = comboBox.get_items().getItem(0).findControl("RadListBox1");
            alert(ListBox.get_selectedItems().length);
        }
    </script>



    -Shinu.
  3. Kathy
    Kathy avatar
    35 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2010 Link to this post

    Can I ask one more favor?  Your code gets me the count of the selected items.  How do I find out how many items there are in the listbox?  I tried  the following but I got a message about object not supporting this method:
    var ListBox = comboBox.get_items().getItem(0).findControl("RadListBox1");
            alert(ListBox.get_items().length);
  4. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 24 Nov 2010 Link to this post

    Hi Kathy,

    In order to get the count of the items in the listbox you should use the following code:
    var ListBox = comboBox.get_items().getItem(0).findControl("RadListBox1");
               alert(ListBox.get_items().get_count());



    All the best,
    Dimitar Terziev
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top