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

Using the RadComboBox with checkboxes and None as a value

9 Answers 272 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Gauri
Top achievements
Rank 1
Gauri asked on 08 Jan 2013, 02:28 PM
I have a radcombobox with checkboxes. Everything works fine. But I need to achieve following. The first value is None and when it is selected all other values must be disabled. So that None and another value are not inserted together.

I will appreciate if someone can help me with this.
Thanks.
Gauri 

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jan 2013, 08:52 AM
Hi Gauri,

Try the following code snippet to achieve your scenario.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" AutoPostBack="true" OnItemChecked="RadComboBox1_ItemChecked">
      <Items>
         <telerik:RadComboBoxItem Text="None" Value="None" />
         .........
     </Items>
</telerik:RadComboBox>

C#:
protected void RadComboBox1_ItemChecked(object sender, RadComboBoxItemEventArgs e)
{
    if (e.Item.Value == "None")
    {
        if (e.Item.Checked == true)
        {
            for (int i = 1; i < RadComboBox1.Items.Count; i++)
            {
                RadComboBox1.Items[i].Enabled = false;
            }
        }
    }
}

Hope this helps.

Regards,
Princy.
0
Gauri
Top achievements
Rank 1
answered on 09 Jan 2013, 11:09 AM
Thanks Princy. 
But my bad. I didn't mention this before that I need to do it client side.
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jan 2013, 02:21 AM
Hi Gauri,

Try the following code snippet to achieve your scenario.

JS:
<script type="text/javascript">
    function OnClientItemChecking(sender, args) {
        if (args.get_item().get_value() == "None") {
            for (var i = 1; i < sender.get_items().get_count(); i++) {
                sender.get_items().getItem(i).disable();
            }
        }
    }
</script>

Hope this helps.

Regards,
Princy.
0
Gauri
Top achievements
Rank 1
answered on 10 Jan 2013, 07:15 PM
That was quite helpful. Thanks.

0
Ramkumar
Top achievements
Rank 1
answered on 06 Dec 2013, 02:17 AM
Hi,
  i have a set of items in radcombobox with checkboxes. If I select(checked) any item, except that item other items must get disabled can u help me in this task?
0
Shinu
Top achievements
Rank 2
answered on 06 Dec 2013, 03:34 AM
Hi Ramkumar,
Please have a look into the following code snippet to achieve your scenario.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" CheckBoxes="true" OnClientItemChecked="OnClientItemChecked1">
    <Items>
        <telerik:RadComboBoxItem Text="Item1" runat="server" />
        <telerik:RadComboBoxItem Text="Item2" runat="server" />
        <telerik:RadComboBoxItem Text="Item3" runat="server" />
        <telerik:RadComboBoxItem Text="Item4" runat="server" />
    </Items>
</telerik:RadComboBox>

JavaScript:
<script type="text/javascript">
    function OnClientItemChecked1(sender, args) {
        if (args.get_item().get_checked() == true) {
            var count = sender.get_items().get_count(), item;
            for (var i = 0; i < count; i++) {
                item = sender.get_items().getItem(i);
                if (item.get_checked() == false) {
                    item.disable();
                }
            }
        }
    }
</script>

Thanks,
Shinu.
0
Ramkumar
Top achievements
Rank 1
answered on 06 Dec 2013, 04:28 AM
Hi Shinu,
  Thanks for ur help. I am writing the code in the Itemchecked event in c# code behind. can u please help in that?.
When I implement in javascript, it throws the error as "Object does not support the property or method"
in the line :for (var i = 0; i < count; i++) {
                item = sender.get_items().getItem(i);
                if (item.get_checked() == false) {
                    item.disable();
0
Shinu
Top achievements
Rank 2
answered on 06 Dec 2013, 07:47 AM
Hi Ramkumar,

Please have a look into the C# code to achieve your scenario.

C#:
protected void RadComboBox1_ItemChecked(object sender, Telerik.Web.UI.RadComboBoxItemEventArgs e)
{
    if (e.Item.Checked == true)
    {
        foreach (RadComboBoxItem item in RadComboBox1.Items)
        {
            if (item.Checked == false)
                item.Enabled = false;
        }
    }
    else
    {
        foreach (RadComboBoxItem item in RadComboBox1.Items)
        {
            item.Enabled = true;
        }
    }
}

I am not getting any error on that line,  can you please check whether you are attaching the correct client side event?
Thanks,
Shinu.
0
Gauri
Top achievements
Rank 1
answered on 13 Dec 2013, 04:59 AM






I am using javascript on OnClientItemChecking. 

I have None at the top and other additional items in the combobox.
When None is selected the other items should be deselected and disabled. 
My javascript is doing that. But the None value gets desected and needs to be selected again.
I also noticed that the javascript is being called twice.

Here is my Javascript .

function OnNCAAClientItemChecking(sender, args) {
                var UINCAAUniqueID = $find($telerik.$("[id$='UINCAAUniqueID']")[0].id);
                var UINCAAUniqueIDTable = UINCAAUniqueID.get_masterTableView();
                var UINCAAUniqueIDRows = UINCAAUniqueIDTable.get_dataItems();
                var UINCAAUniqueIDRowCount = UINCAAUniqueIDRows.length;
                var PatientID = $telerik.$("[id$='HFPatientID']");

                OnNCAAChange(sender, args);
                if (args.get_item().get_text() == "None") {
                    if (args.get_item().get_checked() == true)
                        for (var i = 1; i < sender.get_items().get_count() ; i++) {
                            sender.get_items().getItem(i).enable();
                        }
                    else {

                        if (UINCAAUniqueIDRowCount > 0) {
                            if (confirm('All child records will be deleted. Are you sure you want to proceed?')) {

                                CongWebService.DeleteNCAA(PatientID[0].value);
                                UINCAAUniqueIDTable.rebind();

                                for (var j = 1; j < sender.get_items().get_count() ; j++) {
                                    //sender.get_items().getItem(j).set_checked(false);
                                    sender.get_items().getItem(j).disable();
                                }
                                //sender.trackChanges();
                                //sender.get_items().getItem(0).set_checked(true);
                                //sender.commitChanges();
                                //    CongWebService.InsertNCAA(PatientID[0].value, '3.2');
                            }
                            else {
                                sender.trackChanges();
                                sender.get_items().getItem(0).set_checked(true);
                                sender.commitChanges();
                            }
                        }
                        else {

                            for (var k = 1; k < sender.get_items().get_count() ; k++) {
                                sender.get_items().getItem(k).set_checked(false);
                                sender.get_items().getItem(k).disable();

                            }
                            // CongWebService.InsertNCAA(PatientID[0].value, '3.2');
                        }
                    }
                }
                else {
                    if ((UINCAAUniqueIDRowCount == 1) && sender.get_items().getItem(0).get_text() != "None" && (args.get_item().get_checked() == false)) {
                        if (confirm('Record with value None will be deleted. Are you sure you want to proceed?')) {

                            CongWebService.DeleteNCAA(PatientID[0].value);
                            UINCAAUniqueIDTable.rebind();

                        } else {
                            sender.trackChanges();
                            sender.get_items().getItem(0).set_checked(true);
                            sender.commitChanges();
                        }
                    }
                }
            }


How can I keep the selected value of none?

Thanks in advance.
























































Tags
ComboBox
Asked by
Gauri
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Gauri
Top achievements
Rank 1
Ramkumar
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or