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

Combo box click issue

3 Answers 64 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
RK
Top achievements
Rank 2
RK asked on 12 Feb 2014, 10:59 AM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Feb 2014, 07:23 AM
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.
0
RK
Top achievements
Rank 2
answered on 13 Feb 2014, 08:32 AM
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>
0
Plamen
Telerik team
answered on 17 Feb 2014, 09:08 AM
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.
Tags
ComboBox
Asked by
RK
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
RK
Top achievements
Rank 2
Plamen
Telerik team
Share this question
or