Selecting all items in a group with a checkbox in the group header item

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

    Posted 16 Jan 2007 Link to this post


    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    4.5.0 and later

    2008.1.415 and later
    .NET version 2.0 and later
    Visual Studio version

    2005 and later
    Programming language

    VB and C#
    Browser support

    all supported by RadGrid for ASP .NET

    all browsers supported by RadControls for ASP .NET AJAX

    This project presents how to select/deselect all rows in a group by means of a checkbox residing in each group header. To accomplish this task the grid group header item is modified - the checkbox is added inside the ItemCreated and ItemDataBound event handlers. The duplicate call to CreateHeaderControls() method is because the controls in the group headers should be recreated when the grid is databound as well as on any other postback. The AutoPostBack property of the checkbox control is set to true and all child items involved are selected server-side.

    Alternatively, a checkbox column toggling a server-side item selection might be added. An example of such column may be found here.

    A limitation in this implementation is the fact that group header items text is lost during the process of adding the checkbox.

    Following is the code of the method that adds a checkbox control to grid group header items:

        private void CreateHeaderControls(GridItemEventArgs e) 
            if (e.Item is GridGroupHeaderItem) 
                GridGroupHeaderItem item = e.Item as GridGroupHeaderItem; 
                DataRowView groupDataRow = (DataRowView)e.Item.DataItem; 
                CheckBox check = new CheckBox(); 
                check.AutoPostBack = true
                check.ID = "CheckAll"
                check.Text = "Select all items in group "
                check.CheckedChanged += new EventHandler(check_CheckedChanged); 

        Private Sub CreateHeaderControls(ByVal e As GridItemEventArgs) 
            If TypeOf e.Item Is GridGroupHeaderItem Then 
                Dim item As GridGroupHeaderItem = e.Item 
                Dim check As New CheckBox() 
                check.AutoPostBack = True 
                check.ID = "CheckAll" 
                check.Text = "Select all items in group " 
                AddHandler check.CheckedChanged, AddressOf check_CheckedChanged 
            End If 
        End Sub 
  2. Answer
    8C3261F8-C673-482D-A083-AB251381D20D avatar
    21 posts
    Member since:
    Apr 2008

    Posted 04 Jun 2009 Link to this post

    Thank you for the immediate response.  But in your example the ID and Name for each group is hardcoded.  But in my case, the ID and Name for the Group column will be fetched from the database.  How to set the ID and Name for each group item using the sample code suggested by you.

  3. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 04 Jun 2009 Link to this post

    Hello Badrinarayanan,

    For questions concerning your particular implementation, please use our public forum or support ticket system after logging from your account on our site.

    Best regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top

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