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

Adding an item that's not in the datasource

7 Answers 50 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Kathy
Top achievements
Rank 1
Kathy asked on 22 Nov 2010, 05:24 PM
I'm using a sql datasource to populate my radcombobox.  The combobox is a multiselect with checkboxes.  I would like to add another item, the text would be All and if you select this item, all the checkboxes in the combo would be selected.  I tried in the databound event and it makes the checkbox, but not the text.  Here's the code:
protected void ImpactCombo_DataBound(object sender, EventArgs e)
        {
            RadComboBoxItem all = new RadComboBoxItem("All", "-1");
            ImpactCombo.Items.Add(all);
        }

Any ideas?  Thanks.

7 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 22 Nov 2010, 06:06 PM
Hi Kathy,

After adding the Item to the Items collection, call its DataBind() method:
protected void ImpactCombo_DataBound(object sender, EventArgs e)
{
    RadComboBoxItem all = new RadComboBoxItem("All", "-1");
    ImpactCombo.Items.Add(all);
    all.DataBind();
}

I hope this helps.

Regards,
Simon
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.
0
Kathy
Top achievements
Rank 1
answered on 22 Nov 2010, 06:51 PM
Nope, that didn't help.  Here's what the code-behind looks like:
<telerik:RadComboBox ID="MitigationCombo" Runat="server" 
    DataSourceID="MitigationDS" DataTextField="MitigationName" 
    DataValueField="MitigationID" Skin="Office2007" 
        ondatabound="MitigationCombo_DataBound" Width="487px">
    <ItemTemplate>
        <div onclick="StopPropagation(event)" class="combo-item-template">
            <asp:CheckBox runat="server" ID="chk1" Checked="true" onclick="onCheckBoxClick(this,'Mitigation')"/>
            <asp:Label runat="server" ID="Label3" AssociatedControlID="chk1"><%# Eval("MitigationName") %>
            </asp:Label>
        </div>
    </ItemTemplate>
</telerik:RadComboBox>
0
Simon
Telerik team
answered on 24 Nov 2010, 02:11 PM
Hi Kathy,

This is the definition of another RadComboBox - MitigationCombo - and you are adding the Item to ImpactCombo. What is the definition of ImpactCombo? Am I missing something else?

Sincerely yours,
Simon
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.
0
Kathy
Top achievements
Rank 1
answered on 24 Nov 2010, 04:11 PM
I've redone these radcomboboxes to use a RadListBox.  So I'm still trying to get this "All" entry in the listbox.
<telerik:RadComboBox ID="ImpactCombo" Runat="server"  
    DataTextField="ImpactName" DataValueField="ImpactID" Skin="Office2007" 
        Width="487px">
         <Items><telerik:RadComboBoxItem Text="" />
         </Items>
    <ItemTemplate>
                <div id="div3">
                    <telerik:RadListBox ID="RadListBox3" runat="server" Width="100%" SelectionMode="Multiple"
                        OnClientSelectedIndexChanged="onSelectedIndexChangedImpact" DataSourceID="ImpactDS" DataTextField="ImpactName"
                        DataValueField="ImpactID">
                    </telerik:RadListBox>
                </div>
  
                <script type="text/javascript">
                    var div3 = document.getElementById("div3");
                    div3.onclick = stopPropagation;
                </script>
  
            </ItemTemplate>
</telerik:RadComboBox>
So, this is a radcombobox where the first item is a listbox.  The listbox holds the values from the datasource.  That works fine.  But I still want to add an item to the listbox, the item would be "All" so the user could select that guy and select all the items in the listbox.
0
Dimitar Terziev
Telerik team
answered on 24 Nov 2010, 05:09 PM
Hello Kathy,

We have prepared a small example showing how you could make this "all" item check and uncheck all other items in the listbox. Also we have added a function showing the count of the checked items.
This 'all' item is added using the "DataBound" event  as you will see in the example.


Best wishes,
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.
0
Kathy
Top achievements
Rank 1
answered on 26 Nov 2010, 01:57 AM
Can I ask one last question ( I promise)!!  Your solution works great.  But how would I handle having several radcomboboxes working the same way?  There would have to be some kind of switch so that we would know what was clicked in combo1 versus what was clicked in item2, for example.  I just don't know the javascript call to do that.  So close at this point. 
Thanks for all your help.  You guys are great.
0
Dimitar Terziev
Telerik team
answered on 26 Nov 2010, 01:19 PM
Hi Kathy,

My suggestion is to use the following javascript which gets the ID of the combobox from which the event has been fired.

function onObjectiveDDClosed(sender, e) {
 
    var itemId = sender.get_id();
    var item = sender.get_items().getItem(0);
 
    switch (itemId) {
        case "RadComboBox1":
            getCheckedItems(item);
            break;
        case "RadComboBox2":
            getCheckedItems(item);
            break;
    }
 
}
 
function getCheckedItems(inputParam) {
    var listbox;
    var array;
    listbox = inputParam.findControl("RadListBox1");
    array = listbox.get_checkedItems();
    alert(array.length);
}

I hope this will help.

Regards,
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
Simon
Telerik team
Kathy
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Share this question
or