RadCombobox Check All on Initial Load

12 posts, 1 answers
  1. Ricky
    Ricky avatar
    10 posts
    Member since:
    Apr 2012

    Posted 24 Apr 2012 Link to this post

    Hi,

    I want check all my checkbox on RadCombobox when initial load.
    Is there any feature to do that ?

    Thanks,
    Ricky
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Apr 2012 Link to this post

    Hi Ricky,

    Try the following code to check all checkboxes in a RadComboBox in pageload.

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
       foreach (RadComboBoxItem itm in RadComboBox1.Items)
           {
           itm.Checked = true;
           }
        }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricky
    Ricky avatar
    10 posts
    Member since:
    Apr 2012

    Posted 24 Apr 2012 Link to this post

    Thanks for the quick response..i just thinking if there is another way around other than Princy gave.

    Thanks a lot !!
  5. AR
    AR avatar
    1 posts
    Member since:
    Dec 2012

    Posted 26 Dec 2012 Link to this post

    Hi,

    I have tried two ways of doing it :

    ddlLanguage.ItemDataBound += MultiSelectDropDownItemBound;
     
    private void MultiSelectDropDownItemBound(object sender, RadComboBoxItemEventArgs e)
    {
        e.Item.Checked = true;
    }
     
    private void SelectAllItemsInDropDown(RadComboBox rcbDropDown)
    {
        foreach (RadComboBoxItem rcbItem in rcbDropDown.Items)
            rcbItem.Checked = true;
    }

    In both ways when the page loads we will see all items checked in the dropdown. It also intelligently checks "All Items Checked" checkbox.

    But am facing a problem on trying to unselect all by clicking "Check All". We have to click twice to get this working.

    Is there any fix/workaround or a new property that we can set in the control itself like "AllItemsChecked = true" from server itself?
  6. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 28 Dec 2012 Link to this post

    Hello Ashik,

    Regarding the "Check All" issue that you have to check it twice - I believe the problem is fixed in the latest version - 2012.3.1205.
    Otherwise we haven't such a property about the "AllItemsChecked".

    Regards,
    Helen
    the Telerik team
    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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 01 Apr 2014 Link to this post

    Hi,Bellow code contains RadComboBox with checkbox option,I need help to select all checkboxes when header check box is checked and uncheck header if child checkboxes are unchecked and Iam using Rad controlls for Ajax Q3 2010 version and it not supports checkbox property to select all at all. Please Suggest me some javascript to check all/Uncheack all checkboxes when header is checked.Thank You in advance.
    <telerik:RadComboBox ID="RadComboBox1" Runat="server" OnClientDropDownClosed="onDropDownClosing" HighlightTemplatedItems="true"
                            AllowCustomText="true">
                            
                            <ItemTemplate>
                            <div onclick="StopPropagation(event)">
                                <asp:CheckBox runat="server" ID="chk1"/>
                                    <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1" Text='<%#DataBinder.Eval(Container.DataItem,"Names")%>'/>
                            </div>
                            </ItemTemplate>
                            
                            <HeaderTemplate>
                                <asp:CheckBox ID="chkHeader" runat="server" Text="All"/>
      
                            </HeaderTemplate>
                        </telerik:RadComboBox>
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2014 in reply to Deekshith Link to this post

    Hi Deekshith,

    Please try the following JavaScript code snippet which works as expected for me.

    ASPX:
    ...          
    <HeaderTemplate>
        <asp:CheckBox ID="chkHeader" runat="server" Text="All" onclick="Checked(this);" />
    </HeaderTemplate>
    ...

    JavaScript:
    <script type="text/javascript">
        function Checked(checkbox) {
            var combobox = $find("<%=RadComboBox1.ClientID %>");
            if (checkbox.checked == true) {
                for (var i = 0; i < combobox.get_items().get_count(); i++) {
                    $telerik.findElement(combobox.get_items()._array[i].get_element(), "chk1").checked = true;
                }
            }
            else if (checkbox.checked == false) {
                for (var i = 0; i < combobox.get_items().get_count(); i++) {
                    $telerik.findElement(combobox.get_items()._array[i].get_element(), "chk1").checked = false;
                }
            }
        }
    </script>

    Thanks,
    Princy.
  9. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 02 Apr 2014 in reply to Princy Link to this post

    Thanks for your quick reply Princy.But I'am getting the following error:JavaScript runtime error: Unable to set property 'checked' of undefined or null reference
  10. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 02 Apr 2014 Link to this post

    Thank You Soo Much Princy..its working fine now.Actually i did some thing wrong in my code so i got that error.now its resolved. 
  11. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 02 Apr 2014 Link to this post

    Princy do you know how to uncheck the header when any one checkbox in item template unchecked??
  12. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Apr 2014 in reply to Deekshith Link to this post

    Hi Deekshith,

    Please try the following code snippet which works fine at my end.

    ASPX:
    ...
    <ItemTemplate>
        <div>
            <asp:CheckBox runat="server" ID="chk1" onclick="UncheckHeader(this);" />
            ...
        </div>
    </ItemTemplate>
    ...

    JavaScript:
    function UncheckHeader(checkbox) {
        var combobox = $find("<%=RadComboBox1.ClientID %>");
        if (checkbox.checked == false) {
            var checkbox = document.getElementById('<%=(RadComboBox1.Header.FindControl("chkHeader") as CheckBox).ClientID %>');
            checkbox.checked = false;
        }
    }

    Thanks,
    Princy.
  13. Deekshith
    Deekshith avatar
    15 posts
    Member since:
    Mar 2014

    Posted 02 Apr 2014 Link to this post

    Thank You Princy :)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017