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

Radcombobox witth checkboxes

3 Answers 158 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gauri
Top achievements
Rank 1
Gauri asked on 11 Mar 2015, 02:33 PM
I have a radcombobox with checkboxes. It has a javascript that has to enable another textbox depending on the value of selected item.
The javascript is called when the checkbox is selected but it does not find selected items first time.
when we click second time it finds only the first one. And so on.

I have a code snippet to reproduce this issue. This used to work before I installed updates.
2015.1.225.40 installed.

I am using C# 2012
.net vesrion 4.5

In this code snippet, I am updating  the value of label. The Label shows the values of selected items '-' seperated.
So first time if I select 44 (value 4)  .... The Label shows nothing
then if I select 11(value 1)  .... The Label shows -4
then if I select 77(value 7)  .... The Label shows   -1- 4 
and so on.

I hope I have explained my scenario good enough. Please let me know if you need any more clarification.
------------- Javascript -----------
    function OnNCAAChange(sender, args) {
        var NCAA;
        var Label1;

        NCAA = $telerik.$("[id$='UINCAA']");
        Label1 = $telerik.$("[id$='Label1']");
        Label1[0].textContent = "";
        for (var i = 0; i < sender.get_items().get_count() ; i++) {
            var item = sender.get_items().getItem(i);
            var checkbox = item.get_checkBoxElement();
            if (checkbox.checked) {
                Label1[0].textContent = Label1[0].textContent + ' - ' +  item.get_value();
            }
        }
    }

--------- Controls -----------------
 <telerik:RadComboBox runat="server" ID="UINCAA" Width="60%" CheckBoxes="true" EnableCheckAllItemsCheckBox="false"
                                    OnClientItemChecking="OnNCAAChange" Style="z-index: 8100" MaxHeight="240" ItemsPerRequest="10">
                                </telerik:RadComboBox>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

--------Codebehind -------------
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //List<RadComboBoxItem> rcblist;
            //rcblist = GlobalCodes.GetRCBListBySTSVer(GlobalCodes.Database.STS_Congenital, "3.22", "NCAA", false);

            UINCAA.Items.Clear();
            string t = "1";
            for (int i = 1; i < 10; i++ )
            {
                //RadComboBoxItem hc;
                RadComboBoxItem rc = new RadComboBoxItem();
                rc.Text = t + i.ToString();
                rc.Value = i.ToString();
                UINCAA.Items.Add(rc);

            }
        }

    }

   


3 Answers, 1 is accepted

Sort by
0
Gauri
Top achievements
Rank 1
answered on 11 Mar 2015, 03:27 PM
I noticed something. When we click on the actual checkbox it works fine but when we click on description , the checkbox is selected but the javascript doesn't recognise it.

Thanks in advance.
0
Gauri
Top achievements
Rank 1
answered on 13 Mar 2015, 07:46 PM
we were using OnClientItemChecking event we should use OnClientItemChecked
Another solution is
Instead of
 var checkbox = item.get_checkBoxElement();
           if (checkbox.checked) {
using
if(args.get_item().get_checked() == true)

fixes it while using OnClientItemChecking item
0
Ivan Danchev
Telerik team
answered on 16 Mar 2015, 12:17 PM
Hello,

I'm glad you found a solution.

The OnClientItemChecking event is fired before the items is checked, so, as you found out yourself, the OnClientItemChecked event handler is where you can check if a particular item has been checked and react accordingly.

Regards,
Ivan Danchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Gauri
Top achievements
Rank 1
Answers by
Gauri
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or