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

[Solved] Edit a Group in RadGrid

8 Answers 515 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Redmond Rinehart
Top achievements
Rank 1
Redmond Rinehart asked on 25 Sep 2008, 10:47 PM
Hi there,

Does anyone know of a way to have a RadGrid that uses a grouping, allow the user to edit the group?  Basically, if the user wants, they should be able to put the row of the group in edit mode, as well as the rows beneath each grouping header.

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Sep 2008, 04:46 AM
Hi Redmond,

One suggestion will be to add a button to edit the Grouped items in the GridGroupHeader in the code behind and then perform the edit operation.

CS:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item; 
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem; 
            Button btn = new Button(); 
            btn.ID = "EditButton"
            item.DataCell.Controls.Add(btn); 
        } 
       
    } 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item; 
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem; 
            Button btn = new Button(); 
            btn.ID = "EditButton"
            btn.Click += new EventHandler(btn_Click); 
            item.DataCell.Controls.Add(btn); 
        } 
    } 
    void btn_Click(object sender, EventArgs e) 
    { 
       Button btn = (Button)sender; 
       GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)btn.NamingContainer; 
       GridItem[] children = groupHeader.GetChildItems(); 
            foreach (GridItem child in children) 
           { 
              GridDataItem dataItem = child as GridDataItem; 
              dataItem.Edit = true
            } 
            RadGrid1.Rebind(); 
    } 


Thanks
Shinu
0
Redmond Rinehart
Top achievements
Rank 1
answered on 21 Oct 2008, 04:55 PM
Ok, the code works, but the group headers now no longer display the data that they were before, just default data.  Also, do you know how I can change the information that I'm showing in the group header?  Right now I'm displaying surveydraftid, but I want to display the text value for the id.  This value is pulled in my Linqdatasource that populates the radgrid, but I haven't seen how to show this value without actually grouping on it.  I want to group on the numerical value, but show the text value.  Does that make sense?
0
Redmond Rinehart
Top achievements
Rank 1
answered on 21 Oct 2008, 05:01 PM
I forgot to say before, that I'm using VB.  Also, once the GroupHeader is in edit mode, can I turn the fields into templatefields?  I want to change the textboxes to dropdowns.
0
Ryan
Top achievements
Rank 1
answered on 02 Apr 2009, 10:15 PM
I am implementing this feature myself and have it working as your sample describes.  My issue is I want to have two more buttons, UpdateGroup, and CancelGroupEdit in the header as well.

I can add these buttons in the same as the edit button, but am having trouble switching the visibility so that it works like an Edit Command Column, i.e. in read-only mode, only the EditGroup button is visible (the update/cancel buttons are hidden), and in edit mode, the edit button is hidden while the update/cancel buttons are visible.

I have tried checking the GridGroupHeaderItem's children via the GetChildItems() method to see if they are in edit mode on ItemDataBound, but GetChildItems() isnt returning any children, even though the HasChildren property is true.

How can I accomplish this?

Thanks.
0
Sebastian
Telerik team
answered on 03 Apr 2009, 07:59 AM
Hello Ryan,

Indeed adding controls in the group header will remove the default text value from it as mentioned in the example from the following code library thread on our site:

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

To hide your edit/update/cancel buttons in the header conditionally, you can check whether the RadGrid1.EditIndexes.Count property value is greater than 0 in the ItemCreated server handler. If so, then you need to display the update/cancel buttons only, otherwise you need to show the edit button only.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Ryan
Top achievements
Rank 1
answered on 03 Apr 2009, 04:03 PM

Wouldn't this only work if I had the buttons in the grid header?  This would tell me if something in the grid was being edited, but I need to know if items in the group are being edited, and change the display of the buttons in the group header, not the grid header.

i.e. in Group A, items are being edited, so in the header for Group A, hide the edit button, display the update/cancel buttons
      in Group B, no items are being edited, so in the header for Group B, display the edit button, and hide the update/cancel buttons

is there an equivalent method to RadGrid1.EditIndexes.Count, that works at the group level, similar to
RadGrid1.Groups[x].EditIndexes.Count?

0
Sebastian
Telerik team
answered on 06 Apr 2009, 04:32 PM
Hello Ryan,

Unfortunately the edit functionality you request on a per group level is not supported out-of-the-box.

A possible option for you would be iterate through the GridGroupHeaderItems in the grid using the GetItems(itemType), utilize the GetChildItems() method of each GridGroupHeaderItem instance and check their Edit property value. If one of these child items is edited, change the visibility of the buttons in the corresponding group header.

These actions should take place in the PreRender event of the grid when the child items in each group will be available. I hope these directions are helpful.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Ryan
Top achievements
Rank 1
answered on 09 Apr 2009, 08:23 PM
That worked great...thanks.
Tags
Grid
Asked by
Redmond Rinehart
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Redmond Rinehart
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or