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

RadGrid in RadGrid in FormView

3 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Miranda
Top achievements
Rank 1
Miranda asked on 22 May 2014, 03:20 PM
Hi Folks, first time on this forum so please be gentle.

I have an asp.net Formview with a RadGrid (rgTradeName) inside it.

rgTradeName has two RadGrids nested inside the edit form template (rgAPSummaryEdit & rgAPSummaryEditNew). 

rgAPSummaryEditNew has a grid button column and is fires rgAPSummaryEditNew_ItemCommand when the user clicks on the button.

What I need to do is add the line from rgAPSummaryEditNew that the user has clicked on to the data that populates rgAPSummaryEdit. The hard part is finding rgAPSummaryEdit in the c# page-behind. So far rgAPSummaryEditNew_ItemCommand looks like this:

    protected void rgAPSummaryEditNew_ItemCommand(object sender, GridCommandEventArgs e)
    {
        RadGrid rgTN = (RadGrid)fvLicenceSummary.FindControl("rgTradeName");
        if (rgTN != null)
        {
            
        }
    }

rgTN is not null when I run this, but I have no idea how to loop through rgTN to find rgAPSummaryEdit. I've tried quite a number of things, none of them worked.

Can anyone please tell me how to find this RadGrid nested in a RadGrid Nested in a FormView?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 May 2014, 05:24 AM
Hi Miranda,

I guess you want to access the RadGrid inside EditForm during the Edit and bind it. Please check the following code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <MasterTableView >
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource">
                </telerik:RadGrid>
              </FormTemplate>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.EditCommandName)
  {
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
      GridEditableItem parentItem = e.Item as GridEditableItem;
      RadGrid grid = parentItem.FindControl("RadGrid2") as RadGrid; //Search for the inner RadGrid
      grid.Rebind();
    }
  }
}
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
 (sender as RadGrid).DataSource = GetDataTable("SELECT * FROM Orders ");// bind the RadGrid with data
}

Thanks,
Shinu
0
Miranda
Top achievements
Rank 1
answered on 23 May 2014, 07:22 AM
Hi Shinu, thank you for the reply. The aspx that I have is this:
    <asp:FormView ID="fvLicenceSummary" runat="server" DataSourceID="sdsLicenceSummary" DefaultMode="ReadOnly" OnDataBound="fvLicenceSummary_DataBound" OnItemCommand="fvLicenceSummary_ItemCommand" 
            OnItemUpdating="fvLicenceSummary_ItemUpdating">
        <EditItemTemplate>
            <rad:RadGrid ID="rgTradeName" runat="server">
               <MasterTableView Width="880" CommandItemDisplay="Top" DataSourceID="sdsTradeNames" DataKeyNames="BrandCode">
                  <EditFormSettings EditFormType="Template">
                      <FormTemplate>
                         <rad:RadGrid ID="rgAPSummaryEdit" runat="server" AutoGenerateColumns="false" OnItemDataBound="rgAPSummaryEdit_ItemDataBound">
                             <MasterTableView>
                                <Columns>
                                   <rad:GridBoundColumn HeaderText="Licence Number" DataField="LicenceNumber" />
                                   <rad:GridBoundColumn HeaderText="EV Code" DataField="EVCode" />
                                   <rad:GridButtonColumn ItemStyle-HorizontalAlign="Right" ImageUrl="/images/form_icons/delete.png"
                                       ButtonType="ImageButton" CommandName="Remove" Text="Remove" UniqueName="AlterColumn">
                                   </rad:GridButtonColumn>
                                </Columns>
                              </MasterTableView>
                           </rad:RadGrid>
                           <rad:RadGrid ID="rgAPSummaryEditNew" runat="server" AutoGenerateColumns="false" OnItemCommand="rgAPSummaryEditNew_ItemCommand">
                              <MasterTableView>
                                <Columns>
                                   <rad:GridBoundColumn HeaderText="MA Number" DataField="Description" />
                                   <rad:GridBoundColumn HeaderText="EV Code" DataField="EVCode" />
                                   <rad:GridBoundColumn DataField="LicenceAuthorisedProductCode" Visible="false" />
                                   <rad:GridBoundColumn DataField="LicenceMANumberCode" Visible="false" />
                                   <rad:GridButtonColumn ItemStyle-HorizontalAlign="Right" ImageUrl="/images/grid_icons/AddRecord.gif"
                                      ButtonType="ImageButton" CommandName="Add" Text="Add" UniqueName="AlterColumn">
                                   </rad:GridButtonColumn>
                                </Columns>
                               </MasterTableView>
                              </rad:RadGrid>

And the C# is this:

    protected void rgAPSummaryEditNew_ItemCommand(object sender, GridCommandEventArgs e)
    {
        RadGrid rgTradeName = (RadGrid)fvLicenceSummary.FindControl("rgTradeName");
        if (rgTradeName != null)
        {
            //How do I find rgAPSummaryEdit from here?
        }
    }

So the item command event belongs to the second nested RadGrid (rgAPSummaryEditNew)  that is nested within rgTradeName.and the first line succesfully finds the first nested Radgrid and what I need to know is how to loop through the rgTradeName object in order to find the RadGrid nested within it please?

Put another way, within the item command event I need to have an object which is rgAPSummaryEdit.

Thank you.
0
Shinu
Top achievements
Rank 2
answered on 26 May 2014, 05:54 AM
Hi Miranda,

If you want to access the grid inside EditForm when the main Grid is in editmode, try the following code snippet.

C#:
protected void rgAPSummaryEditNew_ItemCommand(object sender, GridCommandEventArgs e)
{
    RadGrid rgTradeName = (RadGrid)fvLicenceSummary.FindControl("rgTradeName");
    if (rgTradeName != null)
    {
        foreach (GridDataItem item in rgTradeName.EditItems)
        {
          GridEditableItem edititem = (GridEditableItem)item.EditFormItem;
          //Access the grid inside editform
          RadGrid rgAPSummaryEdit = (RadGrid)edititem.FindControl("rgAPSummaryEdit");
        
    }
}

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