Check/uncheck all checkboxes of childstemplates

2 posts, 0 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 08 Apr 2009 Link to this post


    Okay I've got a gridview that has 2 levels: parent, child. 
    Now in both levels I've got a checkbox column.
    So I want to check/uncheck all checkboxes in the child level when I clicked on the parent his checkbox.

    I got it working I thought but I'm getting some strange behavior. I think I know why, but I have no idea for the moment how to solve it.

    okay my code snippet:

    private void rgvAdserverNetwork_ValueChanged(object sender, EventArgs e) 
        var cell = sender as GridDataCellElement; 
        if (cell == null || ((GridViewDataColumn)cell.ColumnInfo).FieldName != "Add"return
        var viewTemp = cell.ViewTemplate; 
        var tempRow = cell.RowElement; 
        var rowinfo = tempRow.RowInfo; 
        if (!(bool)cell.Value) 
            //loop the child items to set the checkbox to true 
            rowinfo.Cells["Add"].Value = true//set the checkbox of the parent to true 
    //loop the child items of the given master row 
    private void loopChilds(GridViewRowInfo masterrow) 
        var childRows = masterrow.ViewTemplate.ChildGridViewTemplates[0].GetChildRows(masterrow); 
        if (childRows == nullreturn
        var length = childRows.Length; 
        var expandedState = masterrow.IsExpanded; 
        masterrow.IsExpanded = true
        for (var i = 0; i < length; i++) 
            childRows[i].Cells["Add"].Value = true//set the checkbox of the parent to true 
        masterrow.IsExpanded = expandedState; 

    Maybe there is a better way to achieve this.

    Thanks a lot in advanced.

  2. Jack
    Jack avatar
    2333 posts

    Posted 10 Apr 2009 Link to this post

    Hi Gerbrand,

    I tested the code and found that exception is fired when you try to check whether a row is not expanded. We located the issue and it will be addressed in the upcoming service pack.

    Could you please specify this strange behavior and we will try to find a solution.

    Sincerely yours,
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top