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

Editable grid inside formtemplate

2 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roy Halvorsen
Top achievements
Rank 1
Roy Halvorsen asked on 06 Aug 2009, 07:29 AM
How can i databind an editable grid (RadGrid2) that is placed inside a formtemplate of another grid (RadGrid1)? And how can I render the RadGrid2 to open all the rows editable at the same time? Using OnNeedDataSource in RadGrid2 doesn't seem to work.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2009, 09:27 AM
Hi Roy,

Here is the sample code to access the Grid inside the EditFormTemplate of another Grid. Try accessing the EditForm Grid in the ItemDataBound event of the Main Grid as shown below.

ASPX:
 
<EditFormSettings EditFormType="template"
                        <FormTemplate> 
                            <telerik:RadGrid ID="RadGrid3" AllowPaging="true" PageSize="5"  AllowMultiRowEdit="true" runat="server"
                             <MasterTableView EditMode="InPlace" ></MasterTableView
                            </telerik:RadGrid> 
                        </FormTemplate> 
                        <EditColumn UniqueName="EditCommandColumn1"  > 
                        </EditColumn> 
                    </EditFormSettings> 

CS:
 
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem editform = (GridEditFormItem)e.Item; 
            RadGrid EditGrid = (RadGrid)editform.FindControl("RadGrid3"); 
 
            //bind the Grid 
            EditGrid.DataSourceID = "SqlDataSource1"
            EditGrid.MasterTableView.Rebind(); 
 
            //to set the Grid in edit mode 
            foreach (GridDataItem item in EditGrid.Items) 
            { 
                item.Edit = true
            } 
            EditGrid.MasterTableView.Rebind(); 
        } 
    } 


Thanks
Shinu

0
Roy Halvorsen
Top achievements
Rank 1
answered on 06 Aug 2009, 10:30 AM
Thanks for your answer.
It works fine, except for if i click on Cancel or Save, the grid inside the formtemplate loses it's datasource and disappears. And I think I will get into more trouble when trying to save or delete data in the rows of the grid. All data is loaded from codebehind, so no markup datasources is in use.
Tags
Grid
Asked by
Roy Halvorsen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Roy Halvorsen
Top achievements
Rank 1
Share this question
or