This is a migrated thread and some comments may be shown as answers.

Grouping - Count Checked Items?

4 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 07 Jan 2009, 05:13 PM
I simply cannot figure out how to do this, and feel like I'm probably missing something pretty basic, but I can't figure it out or find anything in the help/forums.

I've got my grid. Each row has a checkbox.

In my header, i'm counting the total records, but I'd also like the count the total that are checked.

HELP!!

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Jan 2009, 05:36 PM
Hello Daniel,

Please test the attached example and let us know whether this helps.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Daniel
Top achievements
Rank 1
answered on 07 Jan 2009, 05:52 PM
That helps, but I need to be able to display this in a group header. (and I've got multiple levels of grouping).
0
Shinu
Top achievements
Rank 2
answered on 08 Jan 2009, 07:49 AM
Hi Daniel,

Try the following code snippet in order to show the number of the checked rows in the GroupHeader.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    foreach (GridGroupHeaderItem groupHeader in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)) 
    { 
        int count = 0; 
        GridItem[] children = groupHeader.GetChildItems(); 
        foreach (GridItem child in children) 
        { 
            GridDataItem dataItem = child as GridDataItem; 
            if ((child.FindControl("checkbox"as CheckBox).Checked) 
                count++; 
        } 
        groupHeader.DataCell.Text = count.ToString(); 
    } 

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 13 Jan 2009, 07:31 PM
Your code worked, but I had a moment of ingenuity and figured how to do it without any code:

I added a field to my SQL that took my bit and cast it to a tinyint:

cast(Abstracted as tinyint) as AbsNum

From there, I was able to add a column and do a true sum on it.

Just wanted to post for others, if you can't see the forest for the trees like myself!



Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Daniel
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or