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

RadComboBoxItem not detecting selected checkboxes in checkbox template

2 Answers 134 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
darenkov
Top achievements
Rank 1
darenkov asked on 04 Apr 2010, 06:16 PM
Hello,

I have a RadComboBox with a multi-checkbox setup. It is working fine but when try loop through the items and see if anything has been selected it is showing FALSE even when I have definitely selected some items.

My code is as follows:

foreach (RadComboBoxItem rcbi in cmbAccessories.Items) 
     if (rcbi.Selected) 
     { 
         //insert value in database 
     } 


<telerik:RadComboBox ID="cmbAccessories" Width="200px"  
                                OnClientDropDownOpening="OnClientDropDownOpening"  
                                EmptyMessage="...Select Accessories"  
                                OnClientDropDownClosing="OnClientDropDownClosing"  
                                OnClientSelectedIndexChanging="OnClientSelectedIndexChanging"  
                                OnClientBlur="OnClientBlur" DataTextField="Name" DataValueField="AccessoryID"  
                                ValidationGroup="valItem" HighlightTemplatedItems="false"  
                                AllowCustomText="True" Runat="server" ShowDropDownOnTextboxClick="False"  
                                EnableTextSelection="False"
                                <ItemTemplate> 
                                    <asp:CheckBox ID="chkBox" Text='<%#Eval("Name") %>' onclick="checkboxClick();" runat="server" /> 
                                </ItemTemplate>                                 
                                <FooterTemplate> 
                                    <div style="width:100%;" align="center"><asp:Label ID="lblCloseMe" Text="CLOSE [X]" onclick="CloseMe();" style="cursor:pointer;" runat="server" /></div
                                </FooterTemplate> 
                            </telerik:RadComboBox> 


2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Apr 2010, 07:28 AM

Hi,

Since the checBox is placed in ItemTemplate of RadComboBox control, you have to get reference to the checkbox of each radcomboxitem to in order to get the checked items.

C#:

 
protected void Button3_Click(object sender, EventArgs e)  
{  
    foreach (RadComboBoxItem rcbi in RadComboBox1.Items)  
    {  
        CheckBox chk = (CheckBox)rcbi.FindControl("CheckBoxID");  
        if (chk.Checked)  
        {  
            Response.Write(rcbi.Text); // SelectedItem's text  
        }  
    }   

-Shinu.

0
darenkov
Top achievements
Rank 1
answered on 05 Apr 2010, 04:20 PM
Thanks again Shinu.
Tags
ComboBox
Asked by
darenkov
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
darenkov
Top achievements
Rank 1
Share this question
or