CheckBox in Grouped Column

9 posts, 0 answers
  1. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 28 Oct 2008 Link to this post

    I was wondering if you can put a checkbox in the row of a grouped column. This way if I check that checkbox all of the rows in that grouping would get checked, I look forward to your answer. 

    P.S. I don't want to nest queries to achieve this, just one query.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Oct 2008 Link to this post

    Hi Mike,

    Check out the following code library submission which demonstrates how to select/deselect all rows in a group by means of a checkbox residing in each group header.
    Selecting all items in a group with a checkbox in the group header item

    Regards
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rod
    Rod avatar
    23 posts
    Member since:
    Aug 2007

    Posted 30 Oct 2008 Link to this post

    Has anyone found a way to get around the limitation mentioned in this article (group header text disappearing when check box is rendered)?

    I really need this functionality to work properly. I'm surprised this isn't something that's built into the RadGrid.

    Please help. I'm running out time to make this work and might have to scrap my original design if I can't get this to work.

    Thanks,

    Rod
  5. Bodevain Svensson
    Bodevain Svensson avatar
    195 posts
    Member since:
    May 2006

    Posted 31 Oct 2008 Link to this post

    How about extracting the text value from the group header using the DataCell.Text property before adding the checkbox control? I suppose that adding the text value in another LiteralControl or Label to the cell controls collection should do the job.

    Bodevain
  6. Rod
    Rod avatar
    23 posts
    Member since:
    Aug 2007

    Posted 31 Oct 2008 Link to this post

    Hi Bodevain,

    Thanks for the reply.
    That is one of the things I tried:
    On ItemDataBound I added the DataCell.Text value as an item attribute then on ItemCreated (where it gets overwritten), I'd check to see if the attribute was blank and add it back to the check box text property.

    I really don't understand why that didn't work.
    If that's not what you meant, would you be able to post an example?

    Thanks,

    Rod
  7. Bodevain Svensson
    Bodevain Svensson avatar
    195 posts
    Member since:
    May 2006

    Posted 03 Nov 2008 Link to this post

    You have to span your logic in the ItemCreated and ItemDataBound event at the same time because the controls are added on ItemCreated while the data for them is set on ItemDataBound. Therefore if you add the text value on ItemCreated only, it will be erased when the ItemDataBound event is fired. Check out this topic.

    I can not provide a direct example because the process is rather custom and relies on your internal logic - I hope this explanation will put you on the right track.

    Bodevain
  8. antoniodlp
    antoniodlp avatar
    19 posts
    Member since:
    Mar 2007

    Posted 01 Feb 2009 Link to this post

    This is how I solved the problem of having databound group row text in the 'Selecting all items in a group with a checkbox in the group header item' example.

    The solution is to set the CheckBox text in the ItemDataBound event but not in the ItemCreated event.

            static void check_CheckedChanged(object sender, EventArgs e) 
            { 
                CheckBox check = (CheckBox)sender; 
                GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)check.NamingContainer; 
                GridItem[] children = groupHeader.GetChildItems(); 
                foreach (GridItem child in children) 
                { 
                    child.Selected = check.Checked; 
                } 
            } 
     
            protected void RadGrid1_ItemCreated(object source, GridItemEventArgs e) 
            { 
                if (e.Item is GridGroupHeaderItem) 
                { 
                    var item = e.Item as GridGroupHeaderItem; 
                    var check = new CheckBox(); 
                    check.AutoPostBack = true
                    check.ID = "CheckAll"
                    check.CheckedChanged += check_CheckedChanged; 
                    item.DataCell.Controls.Add(check); 
                }  
            } 
     
            protected void RadGrid1_ItemDataBound(object source, GridItemEventArgs e) 
            { 
                if (e.Item is GridGroupHeaderItem) 
                { 
                    var item = e.Item as GridGroupHeaderItem; 
                    var groupDataRow = (DataRowView)e.Item.DataItem; 
                    var check = new CheckBox(); 
                    check.AutoPostBack = true
                    check.ID = "CheckAll"
                    check.CheckedChanged += check_CheckedChanged; 
                    item.DataCell.Controls.Add(check); 
                    check.Text = " " + groupDataRow["State"]; 
                    item.DataCell.Controls.Add(check); 
                } 
            } 

    I think this function should come as standard in RadGrid if possible.
  9. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 02 Feb 2009 Link to this post

    You don't get the following error?
    Sys.WebForms.PageRequestmanagerServerErrorException: State is neither a DataColumn nor a DataRelation for table GroupedTable()

    This is what the error is pointing to?

     

    check.Text =

    " " + groupDataRow["State"];

    Also, what parts of the prior solution are you using? 

     

  10. antoniodlp
    antoniodlp avatar
    19 posts
    Member since:
    Mar 2007

    Posted 02 Feb 2009 Link to this post

    Sorry,

    The error you're seeing is because of groupDataRow["State"]; which is not in your dataset or data source. Change "State" for the name of the field you want to use in the group headers, like "CategoryID" in the example.

    Another diference with the solution is that in my project I pre-set the grouping by using <GroupByExpressions> and don't let the user group dynamically.

    Hope it makes sense
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017