Combo box click issue

4 posts, 0 answers
  1. RK
    RK avatar
    4 posts
    Member since:
    Feb 2014

    Posted 12 Feb 2014 Link to this post

    In Combo box options, when I click on empty space on the dropdown items (other than checkbox and label) the item text is showing in the textbox eventhough check box is not selected.
    Added image for your reference.
    And I tried to find the length of the checked items while drop down closed and if its 0 then am manually clearing out the textbox control.
    Saying that, checked item length is always returns 0.
    Code for your reference.

    function OnClientDropDownClosing(sender, eventArgs) {
                var combo = $find("<%= rcbPatientType.ClientID %>");
                    if (combo.get_checkedItems().length < 1) {
                        combo.set_text("");
                                }
                    }
    In the image you can see the spot I have marked where I click, at that time 'All ' checkbox is not checked but its shown in textbox
    Now what I want is, either click on empty space should not work otherwise the item checkbox should be checked on clicking the equivalent empty space
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 13 Feb 2014 in reply to RK Link to this post

    Hi,

    Please have a look into the sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox1" runat="server"                   OnClientDropDownClosing="OnClientDropDownClosing" EmptyMessage="select 
      OnClientSelectedIndexChanging="OnClientSelectedIndexChanging1">
        <Items>
            <telerik:RadComboBoxItem Text="1" />
            <telerik:RadComboBoxItem Text="2" />
            <telerik:RadComboBoxItem Text="3" />
        </Items>
        <ItemTemplate>
            <asp:CheckBox ID="CheckBox1" runat="server" CssClass="check" />
            <asp:Label ID="Label1" runat="server" Text="L1"></asp:Label>
        </ItemTemplate>
    </telerik:RadComboBox>

    C#:
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (RadComboBoxItem item in RadComboBox1.Items)
        {
            Label l1 = (Label)item.FindControl("Label1");
            l1.Text = item.Text;
        }
    }

    JavaScript:
    <script type="text/javascript">
        function OnClientDropDownClosing(sender, args) {
            var flag = 0;
            var combo = $find("<%= RadComboBox1.ClientID %>");
            for (var i = 0; i < combo.get_items().get_count(); i++) {
                var checkbox = combo.get_items().getItem(i).get_element().getElementsByTagName("input");
                if (checkbox.item().checked == true) {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
                sender.set_text(" ");
        }
        function OnClientSelectedIndexChanging1(sender, args) {
            args.set_cancel(true);
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. RK
    RK avatar
    4 posts
    Member since:
    Feb 2014

    Posted 13 Feb 2014 in reply to Shinu Link to this post

    Ok I have added asp.net checkbox inside Combo box, so how to get that,

    Code for your reference
     <telerik:RadComboBox ID="rcbLocation" runat="server" AllowCustomText="true" CssClass="Status" AutoPostBack="true" OnSelectedIndexChanged="RadCombo_SelectedIndexChanged">
                             <ItemTemplate>
                                           <asp:CheckBox ID="CheckBox" runat="server" Text='<%# DataBinder.Eval(Container, "Text") %>'
                                                          onclick="onTelerikCheckBoxClick(this,'rcbLocation');" />
                              </ItemTemplate>
      </telerik:RadComboBox>
  5. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 17 Feb 2014 Link to this post

    Hi,

    I have tested the issue described in our on-line demo and the checkbox was checked when you click on the item element. Here is a video of my test. Please review it and let me know if the scenario you are trying to achieve is somehow different.

    Regards,
    Plamen
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top