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

Delete Group from Radgrid

2 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kavya
Top achievements
Rank 2
Kavya asked on 13 Jan 2009, 08:00 PM
Hi
I am trying to delete the Complete group from Radgrid.Below is the code i am trying to use

<rad:RadGrid ID="Subsec_grid" Visible="False" Font-Size="X-Large" OnNeedDataSource="Subsec_grid_NeedDataSource" runat="server" EnableAJAX="True" EnableAJAXLoadingTemplate="True"  Skin="WebBlue"  GridLines="None" Width="335px" > 
       <MasterTableView AutoGenerateColumns="False" Width="100%" DataKeyNames="Message,id"  > 
        
 
       <Columns> 
      <rad:GridBoundColumn UniqueName="name" SortExpression="name" ItemStyle-Font-Size="Medium" Groupable="False"  HeaderText="name" DataField="name" > 
                    </rad:GridBoundColumn> 
                     
                    <rad:GridBoundColumn DataField="Message" ItemStyle-Font-Size="Medium" Groupable="False"  UniqueName="Message"  SortExpression="Message"  HeaderText="Message" > 
                    </rad:GridBoundColumn> 
                        <rad:GridTemplateColumn UniqueName="delete" AllowFiltering="False"   > 
                    <ItemTemplate> 
                    <asp:button  ID="del_lnk" runat="server" Text="Inactivate" OnClick="Delete_Section"  /> 
                      
                    </ItemTemplate> 
                        <ItemStyle HorizontalAlign="Left" /> 
                    </rad:GridTemplateColumn> 
                                      
<rad:GridBoundColumn DataField="id" UniqueName="id" Visible="false"></rad:GridBoundColumn> 
                      
                      
       </Columns> 
       
        <GroupByExpressions >   
         
           
                                                <rad:GridGroupByExpression > 
                                                    
                                                    <SelectFields >    
                                                        <rad:GridGroupByField  FieldAlias="no" FieldName="no" HeaderText="Number" />    
                                                          
                                                    </SelectFields>    
                                                    <GroupByFields>   
                                                       
                                                        <rad:GridGroupByField FieldAlias="no" FieldName="no"  HeaderText="Number"  />    
                                                    </GroupByFields>    
                                                </rad:GridGroupByExpression>    
                                            </GroupByExpressions>    
 
           <RowIndicatorColumn Visible="False">  
               <HeaderStyle Width="20px" /> 
           </RowIndicatorColumn> 
           <ExpandCollapseColumn Resizable="False" Visible="False">  
               <HeaderStyle Width="20px" /> 
           </ExpandCollapseColumn> 
           
       </MasterTableView> 
       <ClientSettings EnablePostBackOnRowClick="true"></ClientSettings> 
       </rad:RadGrid> 
When view this i see inactivate button for each and every row.Is there a way i can show that button only for Groupfield which is bside Number.

I know ican use detailtable/ParentTableRelation is there any other simple way i can just add delete button to Groupfield

Thanks
Kavya

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Jan 2009, 11:33 AM
Hello Kavya,

You can try out the following code to achieve the required scenario
cs:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; 
            string strtxt = groupHeader.DataCell.Text; 
            Button btn = new Button(); 
            btn.ID = "del_lnk"
            btn.Text = "Inactivate"
            btn.Click += new EventHandler(btn_Click); 
            Label lbl = new Label(); 
            lbl.ID = "Label"
                         
            Table table = new Table(); 
            TableRow row = new TableRow(); 
            table.Rows.Add(row); 
            TableCell cell1 = new TableCell(); 
            cell1.Controls.Add(btn); 
            TableCell cell2 = new TableCell(); 
            cell2.Controls.Add(lbl); 
            table.Rows[0].Cells.Add(cell1); 
            table.Rows[0].Cells.Add(cell2); 
 
            groupHeader.DataCell.Controls.Add(table); 
        }       
   } 
 
  void btn_Click(object sender, EventArgs e) 
    { 
        Button btn = (Button)sender; 
        GridGroupHeaderItem grpHeader = (GridGroupHeaderItem)btn.NamingContainer; 
        GridItem[] children = grpHeader.GetChildItems();// to access the child items for the group         
        //delete query 
        RadGrid1.Rebind(); 
    } 
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if(e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; 
            string strtxt = groupHeader.DataCell.Text; 
            Button btn = new Button(); 
            btn.ID = "del_lnk"
            btn.Text = "Inactivate"
            Label lbl = new Label(); 
            lbl.ID = "Label"
            if (strtxt != "&nbsp;") 
                lbl.Text = strtxt
            
            Table table = new Table(); 
            TableRow row = new TableRow(); 
            table.Rows.Add(row); 
            TableCell cell1 = new TableCell(); 
            cell1.Controls.Add(btn); 
            TableCell cell2 = new TableCell(); 
            cell1.Controls.Add(lbl); 
            table.Rows[0].Cells.Add(cell1); 
            table.Rows[0].Cells.Add(cell2); 
 
            groupHeader.DataCell.Controls.Add(table); 
        }              
    } 

Thanks
Princy.
0
Kavya
Top achievements
Rank 2
answered on 14 Jan 2009, 04:26 PM
Princy

Grs8 it works now

Thanks alot

Kavya
Tags
Grid
Asked by
Kavya
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Kavya
Top achievements
Rank 2
Share this question
or