Using the RadComboBox with checkboxes and None as a value

10 posts, 1 answers
  1. Gauri
    Gauri avatar
    32 posts
    Member since:
    Jan 2012

    Posted 08 Jan 2013 Link to this post

    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 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Jan 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gauri
    Gauri avatar
    32 posts
    Member since:
    Jan 2012

    Posted 09 Jan 2013 Link to this post

    Thanks Princy. 
    But my bad. I didn't mention this before that I need to do it client side.
  5. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Jan 2013 Link to this post

    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.
  6. Gauri
    Gauri avatar
    32 posts
    Member since:
    Jan 2012

    Posted 10 Jan 2013 Link to this post

    That was quite helpful. Thanks.

  7. Ramkumar
    Ramkumar avatar
    12 posts
    Member since:
    Nov 2013

    Posted 05 Dec 2013 Link to this post

    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?
  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Dec 2013 Link to this post

    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.
  9. Ramkumar
    Ramkumar avatar
    12 posts
    Member since:
    Nov 2013

    Posted 05 Dec 2013 Link to this post

    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();
  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Dec 2013 Link to this post

    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.
  11. Gauri
    Gauri avatar
    32 posts
    Member since:
    Jan 2012

    Posted 12 Dec 2013 Link to this post







    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.
























































Back to Top
UI for ASP.NET Ajax is Ready for VS 2017