Check/Uncheck all checkboxes in template column and selecting rows with checkbox

Thread is closed for posting
10 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 21 Jul 2006 Link to this post

     

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    3.5.1 and later


    2008.1.415 and later

    .NET version

    1.x (RadGrid for ASP .NET)


    2.0 and later (RadControls for ASP .NET AJAX)

    Visual Studio version

    2002/2003 (RadGrid for ASP .NET)


    2005 and later(RadControls for ASP .NET AJAX)

    Programming language

    C#, VB.NET

    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX



    PROJECT DESCRIPTION
    The demo presents how to check/uncheck all grid rows upon clicking the checkbox inside a template column HeaderTemplate. To accomplish this task we attach the CheckAll() function to the onclick attribute of the checkbox inside the column header.

    In addition, row selection is enabled (AllowRowSelect = true) which allows each item to be selected when clicking on a grid row with the mouse or clicking the checkbox inside the row.


    Note: The last active item in the grid will retain highlighted when you check/uncheck all rows from the checkbox in the header. You can modify the application to extend the check/uncheck/selection logic as per your custom requirements.
     
  2. CB98EDF8-26A8-4351-B9D3-C9910B4CAC23
    CB98EDF8-26A8-4351-B9D3-C9910B4CAC23 avatar
    67 posts
    Member since:
    Sep 2006

    Posted 18 Oct 2006 Link to this post

    So how can you do this if you have more than one column of checkboxes.   Say one for accept and the other for deny.  This will check every checkbox in the grid?
  3. CB98EDF8-26A8-4351-B9D3-C9910B4CAC23
    CB98EDF8-26A8-4351-B9D3-C9910B4CAC23 avatar
    67 posts
    Member since:
    Sep 2006

    Posted 18 Oct 2006 Link to this post

    Might as well answer my own question!


       
    function CheckAllDeny()  
                {   
                      isChecked = !isChecked;  
                        
                        var checkboxes = NegotiationsGrid.MasterTableView.Control.getElementsByTagName("INPUT");  
                        var index;  
                          
                        for(index = 0; index < checkboxes.length; index++)  
                        {  
                          if(checkboxes[index].id.indexOf("Deny")!=-1)  
                          {  
                              if(isChecked)  
                              {  
                                checkboxes[index].checked = true;  
                              }    
                              else  
                              {  
                                checkboxes[index].checked = false;  
                              }  
                          }  
                        }  
                }  
     
     
    function CheckAllAccept()  
                {   
                      isChecked = !isChecked;  
                        
                        var checkboxes = NegotiationsGrid.MasterTableView.Control.getElementsByTagName("INPUT");  
                        var index;  
                          
                        for(index = 0; index < checkboxes.length; index++)  
                        {  
                          if(checkboxes[index].id.indexOf("Accept")!=-1)  
                          {  
                              if(isChecked)  
                              {  
                                checkboxes[index].checked = true;  
                              }    
                              else  
                              {  
                                checkboxes[index].checked = false;  
                              }  
                          }  
                        }  
                } 
  4. B89B5FDB-B49C-4F83-9ECB-591C910B69FF
    B89B5FDB-B49C-4F83-9ECB-591C910B69FF avatar
    2 posts
    Member since:
    Mar 2004

    Posted 05 Dec 2006 Link to this post

    I tried this, but the selection goes off when I switch to a different row. This results in a problem since the items selected using checkbox are not getting in the API call "RadGrid1.SelectedItems"

    If the above method is not applicable for arriving the currently selected items, is there any other way to diffrentiate the check box selected items during page postback?
  5. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 05 Dec 2006 Link to this post

    Hi Jose,

    The example presents single row selection combined with check all functionality for rows with checkbox. If you want to enable multi-row selection set the AllowMultiRowSelection property of the grid to true.
    The selected items should be available on the server through the SelectedItems collection of the grid. You can test the attached project to verify that.

    Best regards,
    Stephen
    the telerik team
  6. 5EA4EB8F-CC64-423C-94B8-5CD08FDF255B
    5EA4EB8F-CC64-423C-94B8-5CD08FDF255B avatar
    13 posts
    Member since:
    Dec 2006

    Posted 04 Jan 2007 Link to this post

    Hello,

    I have tried the demo and it works fine.

    But in addition, the table should be re-sortable, so I have set AllowSorting to true.

    The problem is that when the user clicks a columnheader and the table is resorted, all checkboxes are unchecked.
    I want all checkboxes to keep it state.

    I have managed to do this for the checkboxes on the rows, but I can't find out how to keep the 'master'-checkbox (in the header) checked (if it is), basically because I don't know how to get a reference to that checkbox in the code-behind.

    Does anyone knows how to do this. I guess you should start with the GridTemplateColumn that contains the checkboxes?

    Thanks for any help.
    Gerard
  7. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 04 Jan 2007 Link to this post

    Hello Gerard,

    When you click a column header the grid automatically rebinds in order to sort its records and display them in the corresponding sequence. That is the reason the checked state for the checkboxes inside the template column is lost. To persist their state, you may take advantage of the technique presented in this topic from the product documentation.

    Additionally, to obtain reference to the checkbox inside the column header, you can call the GetItems(itemType) method of the master/detail table and invoke the FindControl(controlId) method for the header item to locate the checkbox in the respective column header.

    Best regards,
    Stephen
    the telerik team
  8. 5EA4EB8F-CC64-423C-94B8-5CD08FDF255B
    5EA4EB8F-CC64-423C-94B8-5CD08FDF255B avatar
    13 posts
    Member since:
    Dec 2006

    Posted 05 Jan 2007 Link to this post

    It works!!
    Thanks a lot, Stephen.

    Gerard
  9. CA745BB0-8721-42EE-81DC-D6E6CF6C9A50
    CA745BB0-8721-42EE-81DC-D6E6CF6C9A50 avatar
    16 posts
    Member since:
    Aug 2005

    Posted 02 Jun 2010 Link to this post

    Stephen, good day.

    Two questions.

    1. Is there a way to check /unckeck all the checkboxes of different grids with the same function may be by sending the grid as parameter?

    2. How do I trigger a postback with the header checking or un checking?

    My best regards.
  10. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 02 Jun 2010 Link to this post

    Hello Alfonso,

    RadGrid for ASP.NET AJAX provides build-in GridClientSelectColumn and server selection with checkboxes as illustrated in these demos:

    http://demos.telerik.com/aspnet-ajax/grid/examples/client/selecting/defaultcs.aspx
    http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectrowwithcheckbox/defaultcs.aspx

    I think that you can use them as a starting point for your custom implementation.

    Best regards,

    Sebastian

    the Telerik team


    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.