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

[Solved] Adding Button Control to GroupHeader

5 Answers 389 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brenda
Top achievements
Rank 1
Brenda asked on 20 Jun 2008, 11:29 AM
Hi,
In my application I would like to add a Button for each group header.
When the user clicks on the Button I want him to be able to insert a new record.
In order for the Insert to work I need to read an ID field value, which is used to Group the records (GroupID).

Here's what I have been able to get so far:
1.I was able to add button to GroupHeader in the Grid's ItemCreated event:
======
if (e.Item is GridGroupHeaderItem)
                {
                    GridGroupHeaderItem groupHeader=         (GridGroupHeaderItem)e.Item;
                   
                    Button objButton = new Button();
                    objButton.CommandName = "Add";
                    objButton.ID = "Button_Add";
                    objButton.Text = "Add ";
                    groupHeader.Cells[0].Controls.Add(objButton);
                   
                }

====

2. Now when the User Clicks on the Button I can get the GroupHeaderItem for which the Button was clicked by interception the ItemCommand Event.

3.I used the FireCommandEvent("InitInsert", string.Empty); to get the Insert input boxes. One problem here is that the Inser section comes on the Last page of the Grid (Paging enabled) can this be fixed?

4. My Main concern is that I am not able to get the GroupID (field in my DB) that is used in GridGroupByField  at design time.
I need this value to be able to insert the record. Is there a way to do this?
I can get this value from the GroupHeader or from any Row in the Group, where the Button was clicked.

Thanks for your help.

-Brenda

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Jun 2008, 12:22 PM
Hi,

Try the following code snippet to stop the insert form appearing on the last page of the Grid.

VB:
Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand       
        If e.CommandName = RadGrid.InitInsertCommandName Then       
            e.Canceled = True      
            e.Item.OwnerTableView.IsItemInserted = True      
            e.Item.OwnerTableView.Rebind()       
            Return       
        End If     


Princy.
0
Brenda
Top achievements
Rank 1
answered on 20 Jun 2008, 01:52 PM
Thanks for the Input. I will try the code.
Could you also possible recommend some solution for reading the FieldValue associated to the GroupHeaderItem where I have inserted the Button.
I have mentioned the scenario in my original post.

Thanks,
Brenda.
0
Shinu
Top achievements
Rank 2
answered on 23 Jun 2008, 10:07 AM
Hi Brenda,

Try the following code snippet.

CS:
  protected void RadGrid2_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridGroupByExpression exp in RadGrid2.MasterTableView.GroupByExpressions) 
        { 
            foreach (GridGroupByField fld in exp.GroupByFields) 
            { 
                string strField = fld.FieldName.ToString(); 
            } 
        } 
    } 


Thanks
Shinu.
0
Ryan
Top achievements
Rank 1
answered on 16 Apr 2009, 11:05 PM
The code for preventing the insert row from being on the last page of the grid ends up putting the insert row at the top of the current page in the grid.  This is close to what I am looking for, but not quite.  I have the Add New Record button in each Group Header, is there a way to put the Insert row at the beginning or end of the group's rows?
0
Princy
Top achievements
Rank 2
answered on 23 Apr 2009, 07:25 AM
Hi Ryan,

I believe there is no direct way to place the insert form  at the end or beginning of a group. A suggestion though would be to use a NestedviewTemplate and design the insert form accordingly . You can expand the insert form for the first or the last row in the group by looping through the group collection.

Telerik has provide  several properties explained in the link below where you can change the position of the insert form (eg:current page,last page..).

http://www.telerik.com/help/aspnet-ajax/grdcustomizeinsertformposition.html

Thanks,
Princy
Tags
Grid
Asked by
Brenda
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Brenda
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Share this question
or