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

Trying to add a value to a RadListBox

3 Answers 55 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kathy
Top achievements
Rank 1
Kathy asked on 24 Nov 2010, 09:37 AM
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.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 24 Nov 2010, 02:12 PM
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.
0
Kathy
Top achievements
Rank 1
answered on 24 Nov 2010, 03:15 PM
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);
0
Dimitar Terziev
Telerik team
answered on 24 Nov 2010, 04:11 PM
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.
Tags
ComboBox
Asked by
Kathy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Kathy
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or