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

Accessing Checkbox in GroupHeader not working

6 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Torsten
Top achievements
Rank 1
Torsten asked on 25 Feb 2011, 10:34 AM
Hi,

I am facing another Problem with RadGrid:

I have grouped my data and added a checkbox to the groupheader with this code:

protected void rtl_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                DataRowView groupDataRow = (DataRowView)e.Item.DataItem;
  
                CheckBox chk = new CheckBox();
                item.DataCell.Controls.Add(chk);
            }
}

This is working. Every groupheader contains a checkbox.

After a postback, I want to get the state of this checkbox:

foreach (GridGroupHeaderItem headerItem in rtl.MasterTableView.GetItems(GridItemType.GroupHeader))
                {
                      
                        CheckBox chkbx = (CheckBox)headerItem.DataCell.Controls[0];                                           
                }

But now,  the controls collection of the headeritem.DataCell is empty. What is wrong here?

6 Answers, 1 is accepted

Sort by
0
JSJ
Top achievements
Rank 1
answered on 25 Feb 2011, 12:02 PM
Hi Torseton,

When you add a control in the RadGrid's ItemDataBound event, the control does not persist on postback. So try adding the control on the ItemCreated event of RadGrid so that the control persists after a postback.
0
Shinu
Top achievements
Rank 2
answered on 25 Feb 2011, 12:08 PM
Hello,

One suggestion is to create the GroupHeader control  in both ItemCreated and ItemDataBound event. Here is sample code.

C#:
protected void rtl_ItemCreated(object sender, GridItemEventArgs e)
    {
         if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                CheckBox chk = new CheckBox();
                item.DataCell.Controls.Add(chk);
            }
    }
protected void rtl_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridGroupHeaderItem)
            {
                GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
                CheckBox chk = new CheckBox();
                item.DataCell.Controls.Add(chk);
            }
        }


-Shinu.
0
Torsten
Top achievements
Rank 1
answered on 25 Feb 2011, 01:32 PM
Thanks for suggestions, but it is still not working. I used your code and now the collection isn`t empty any more.

But:

The checkbox-state is always false. So it isn`t working for me.
0
Pavlina
Telerik team
answered on 25 Feb 2011, 02:57 PM
Hello Torsten,

You may consider using the example from this code library thread and see if it helps:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/selecting-all-items-in-a-group-with-a-checkbox-in-the-group-header-item.aspx

Greetings,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Torsten
Top achievements
Rank 1
answered on 25 Feb 2011, 03:33 PM
Hi have already implemented a function to select/deselect all members of a group. This works fine for me.

But:

I want to save either the groupname or the groupmembers if only some members are selected.

Let me explain:

I have A, B, C, D as values. A and B are members of Group G1, C and D are in G2.

The user has now the possibility to select A and B or the whole group G1. The whole group means: if C or D will go to group G1, they are selected too, otherwise not.

So it is important to get the state of the checkbox.
0
Pavlina
Telerik team
answered on 02 Mar 2011, 02:24 PM
Hi Torsten,

Based on the supplied information, it is hard to determine what is causing this unwanted behavior. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and advise you further.

Greetings,
Pavlina
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Torsten
Top achievements
Rank 1
Answers by
JSJ
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Torsten
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or