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

[Solved] checkboxlist in itemtemplate

5 Answers 301 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
NS
Top achievements
Rank 1
NS asked on 05 May 2008, 03:10 PM
Hello,
Consider the following html code:
 <telerik:RadComboBox runat="server" AutoPostBack="true" Skin="Hay" ID="rcbEnvironments">  
                <ItemTemplate> 
                    <asp:CheckBoxList runat="server" DataTextField="Name" DataValueField="Id" ID="cblEnvironments" /> 
                </ItemTemplate> 
                </telerik:RadComboBox> 

How do I from codebehind databind the checkboxlist ?

If I try (checkboxlist)rcbEnvironments.FindControl("cblEnvironments"), I get a null.

Thanks,
Nicolas

5 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 05 May 2008, 03:13 PM
Hi NS,

The template is instantiated in the context of the specific item, but not the RadComboBox control. Therefore you should use

RadComboBoxItem item = rcbEnvironments.Items[0];
CheckBoxList myList = (CheckBoxList)item.FindControl("cblEnvironments");

I hope this helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
NS
Top achievements
Rank 1
answered on 05 May 2008, 03:19 PM
Hi,
I get a Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.ArrayList.get_Item(Int32 index) exception at the line: RadComboBoxItem item = rcbEnvironments.Items[0];

Must I databind my datasource to the radcombobox ?
0
NS
Top achievements
Rank 1
answered on 05 May 2008, 03:23 PM
Already answered my own question :-) I must indeed databind my datasource to the radcombobox first.

Nicolas
0
NS
Top achievements
Rank 1
answered on 06 May 2008, 07:38 AM
I have some extra questions.

When I expand my radcombobox, my asp:checkboxlist appear. I want to select some items in the checkboxlist.

Problem is when I select one thing, my radcombobox collapses again. I have to expand the radcombobox to select the next thing.

Next question:
Where do I handle the selectedindexchanged of the asp:checkboxlist ? (to get all the checked items), the asp:checkboxlist is not known in codebehind because it is inside a radcombobox.

Thanks,
Nicolas
0
Nikolay
Telerik team
answered on 06 May 2008, 11:54 AM
Hello NS,

  1. You can hook on the OnClientSelectingIndexChanging event of the combobox and call the event arguments' set_cancel(true) method to cancel the event. Thus, the drop-down will not be closed when checking a checkbox:

    function OnClientSelectedIndexChanging(sender, args)
    {
       args.set_cancel(true);
    }
  2. As for the selectedindexchangedof the checkbox list - you should simply hook on the event as if the checkboxlist was not in a combobox' tempate and execute your logic in the event handler
Hope this helps.

Sincerely yours,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
NS
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
NS
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or