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

[Solved] Select Group collection

2 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SCD
Top achievements
Rank 1
SCD asked on 23 Jun 2009, 07:50 PM
I'm looking for a way to get the other items in a group when one is selected.  My grid has data grouped in the following manner.

Policy Number 1
    Customer Id 1
    Customer Id 2
    Customer Id 3

Policy Number 2
    Customer Id 4
    Customer Id 5
    Customer Id 6

If a user selects Costomer 2 I'd want to get the other 2 customer Ids that are in the Policy Number 1 group.


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 24 Jun 2009, 04:43 AM
Hi SCD,

You can achieve this with the help of a GridTemplateColumn with a CheckBox in its ItemTemplate. In the CheckChanged event of the CheckBox you can perform the following code logic to select the other rows inside a particular Group.

ASPX:
 
<telerik:GridTemplateColumn UniqueName="TempCol" HeaderText="SelectColumn"  > 
                  <ItemTemplate> 
                     <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server">         
                     </asp:CheckBox>    
                </ItemTemplate> 
  </telerik:GridTemplateColumn> 

CS:
 
protected void ToggleRowSelection(object sender, EventArgs e) 
    { 
 
        CheckBox chkbx = (CheckBox)sender; 
        GridDataItem item = (GridDataItem)chkbx.NamingContainer; 
        int CurrentGroupIndex =Convert.ToInt16(((Telerik.Web.UI.GridItem)(item)).GroupIndex.Split('_')[0]); 
 
        foreach (GridGroupHeaderItem GroupHeader in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)) 
        { 
            if (Convert.ToInt16(GroupHeader.GroupIndex) == CurrentGroupIndex) 
            { 
                GridItem[] children = GroupHeader.GetChildItems(); 
                foreach (GridItem child in children) 
                { 
                    GridDataItem childItem = (GridDataItem)child; 
                    CheckBox chkbx1 = (CheckBox)childItem.FindControl("CheckBox1"); 
                    chkbx1.Checked = chkbx.Checked; 
                    childItem.Selected = chkbx.Checked; 
 
                } 
            } 
        } 
        
        
    } 


Thanks
Shinu.



0
SCD
Top achievements
Rank 1
answered on 24 Jun 2009, 06:51 PM
Shinu,

Thank you, that's what I was looking for.
Tags
Grid
Asked by
SCD
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
SCD
Top achievements
Rank 1
Share this question
or