Accessing a radGrid that is nested inside another radGrid

8 posts, 0 answers
  1. Aye Myint
    Aye Myint avatar
    3 posts
    Member since:
    Jan 2010

    Posted 10 Feb 2010 Link to this post

    Hi,

     

    I want to be able to access a radGridthat is nested inside a radGrid then populate the nested radGrid from theOnEditCommand of the parent radGrid.

     

    For example: radGrid1 containsradGrid2 within the EditFormSettings.FormTemplate. OnItemCommand, I want todisplay custom formatting for my edit form as well as a new radGrid with otherinformation. Is this possible?

     

    I have tried using thee.item.findControl(“radGrid2”) from the GridCommandEventArgs, but null isreturned. In fact, any object I have within the EditFormSettings.FormTemplateseems to be inaccessible using this syntax. Since this didn’t work, I triediterating through the radGrid1’s items and searched for theGridItemType.EditFormItem and tried locating radGrid2 that way, but also wasunsuccessful.

    protected void RadGrid1_OnEditCommand( object sender, GridCommandEventArgs e )  
            {  
                RadGrid masterGrid = (RadGrid) sender;  
                foreach ( GridItem gi in masterGrid.Items )  
                {  
                    if ( gi.ItemType == GridItemType.EditFormItem )  
                    {  
                        TextBox textBox1 = (TextBox) e.Item.FindControl( "txtCreditorName" );  
                        RadGrid radGrid2 = (RadGrid) e.Item.FindControl( "RadGrid2" );                      
                    }  
                }  
            }  
     

     

     I looked into the thread whichis talking about <NestedViewTemplate> but that is different from what Iwanted to do.

    Can you please take a look at it? Anyhelp would be greatly appreciated.

     

     Here is  my code in aspxpage.

                <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" Width="100%"  
                    AutoGenerateColumns="False" GridLines="None" Height="100%" onneeddatasource="RadGrid1_NeedDataSource" 
                    onupdatecommand="RadGrid1_UpdateCommand"  oneditcommand="RadGrid1_EditCommand" onupdatecommand="RadGrid1_InsertCommand"
                     
                <PagerStyle Mode="NumericPages" AlwaysVisible="True" />                
                <MasterTableView CommandItemDisplay="Top" Width="100%" AllowMultiColumnSorting="True" EditMode="PopUp" 
                    DataKeyNames="creditor_id" Name="creditor">    
                     
                     <Columns>                     
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                            <HeaderStyle Width="30px" /> 
                            <ItemStyle CssClass="MyImageButton" /> 
                        </telerik:GridEditCommandColumn> 
                        <telerik:GridBoundColumn SortExpression="creditor_id" HeaderButtonType="TextButton" DataField="creditor_id" 
                            HeaderText="Creditor Id" UniqueName="creditor_id" ReadOnly="true" Display="false"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn SortExpression="Name" HeaderButtonType="TextButton" DataField="Name" HeaderText="Creditor Name" 
                            UniqueName="Name"
                        </telerik:GridBoundColumn> 
     
                    </Columns>                  
                            
     
               <EditFormSettings EditFormType="Template" PopUpSettings-Height="300px" PopUpSettings-Width="450px"
                         
                        <EditColumn UniqueName="EditCommandColumn1"
     
                        </EditColumn> 
                        <FormTemplate> 
                            <table id="tblCreditor" cellspacing="5" cellpadding="1" width="450" border="0" rules="none"
                                <tr> 
                                    <td> 
                                        Creditor Name: 
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="txtCreditorName" runat="server" Text='<%# Bind( "Name") %>'</asp:TextBox> 
                                    </td> 
                                </tr> 
     
                                <tr> 
                                    <td> 
                                         
                                       <telerik:RadGrid ID="RadGrid2" runat="server" Width="100%"
     
                                        <PagerStyle Mode="NumericPages" AlwaysVisible="True" />                
                                        <MasterTableView CommandItemDisplay="Top" Width="100%" AllowMultiColumnSorting="True"  
                                            DataKeyNames="person_id" Name="contact"
     
                                             <Columns> 
                                                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn2"
                                                    <HeaderStyle Width="30px" /> 
                                                    <ItemStyle CssClass="MyImageButton" /> 
                                                </telerik:GridEditCommandColumn> 
                                                <telerik:GridBoundColumn SortExpression="person_id" HeaderText="Person Id" HeaderButtonType="TextButton" 
                                                    DataField="person_id" UniqueName="person_id" ReadOnly="true" Display="false"
                                                </telerik:GridBoundColumn> 
                                                <telerik:GridBoundColumn SortExpression="Name" HeaderText="Contact Name" HeaderButtonType="TextButton" 
                                                    DataField="Name" UniqueName="Name"
                                                </telerik:GridBoundColumn> 
                                                <telerik:GridBoundColumn SortExpression="Description" HeaderText="Description" HeaderButtonType="TextButton" 
                                                    DataField="Description" UniqueName="Description"
                                                </telerik:GridBoundColumn> 
                                            </Columns> 
                        
                                        </MasterTableView> 
                                      </telerik:RadGrid>                    
                                                      
                                 </td> 
                                </tr> 
                                <tr> 
                                    <td align="center" colspan="2"
                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' 
                                            ValidationGroup="creditor" TabIndex="7"></asp:Button>&nbsp; 
                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" 
                                            TabIndex="8"
                                        </asp:Button> 
                                    </td> 
                                </tr> 
                            </table> 
                        </FormTemplate> 
     
                       <PopUpSettings Height="300px" Width="450px"></PopUpSettings> 
                         
                    </EditFormSettings> 
                </MasterTableView> 
                </telerik:RadGrid> 
     



  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Feb 2010 Link to this post

    Hi Aye Myint,

    You can access the inner radgrid in the ItemDataBound event of parent grid.

    C#:
     
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
            { 
                GridEditFormItem editItem = (GridEditFormItem)e.Item; 
                TextBox textBox1 = (TextBox)editItem.FindControl("txtCreditorName"); 
                RadGrid radGrid2 = (RadGrid)editItem.FindControl("RadGrid2");             
            } 
        } 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aye Myint
    Aye Myint avatar
    3 posts
    Member since:
    Jan 2010

    Posted 12 Feb 2010 Link to this post

    Hi Shinu,

    Thanks for your code. That was really helpful to me.
    Now I'm able to display the RadGrid2 inside the edit form of RadGrid1. What I need to do is that RadGrid2 should also have insert, edit and delete buttons. So I put another <EditFormSettings> code blog in my RadGrid2.

    When I click on a edit button in RadGrid1, it pop-ups the right edit form. Then in that pop-up form, I have my RadGrid2 with edit buttons. The problem I'm having now is when I click on a edit button in RadGrid2, it pop-ups the RadGrid1's edit form instead of the corresponding one. 

    Here is how I databind my RadGrid2.
     
            protected void RadGrid1_ItemDataBound( object sender, GridItemEventArgs e )  
            {  
                if ( e.Item is GridEditableItem && e.Item.IsInEditMode )  
                {  
                    GridEditableItem item = e.Item as GridEditableItem;  
      
                    RadGrid grid2 = item.FindControl( "RadGrid2" ) as RadGrid;  
      
                    if ( grid2 != null )  
                    {  
                        var datasource = ( some linq to sql query here );  
                        grid2.DataSource = datasource;  
                        grid2.DataBind();  
                    }  
                }  
            } 

    What I should do to have my RadGrid2 with the insert, edit and delete abilities from this point?
     Thanks again.

    Aye
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 15 Feb 2010 Link to this post

    Hello Aye,

    Please, consider using advanced binding through the NeedDataSource event of the grid instead of simple binding with DataBind() calls. Have in mind that simple data-binding can be used in simple cases when you do not require the grid to perform complex operations such as: Inserting, deleting, and updating records through custom edit forms (WebUserControl or FormTemplate)

    I hope this helps.

    Regards,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Andrew
    Andrew avatar
    9 posts
    Member since:
    Feb 2009

    Posted 07 Mar 2010 Link to this post

    I have also posted this on another thread. 

    I need to do the same thing.  I need to edit a grid that is inside another grid.  Populating the inner grid is not an issue.  the problem comes when I hit the Edit button.  I cannot gain access to the Object that the row to be edited is bound to. 

    Help!!!
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 10 Mar 2010 Link to this post

    Hello Andrew,

    Please, examine the online resources below, for more information about how to achieve your goal.
    Update/Insert/Delete in Hierarchy
    Accessing cells and rows

    Kind regards,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. sreelatha bora
    sreelatha bora avatar
    4 posts
    Member since:
    Mar 2010

    Posted 28 Mar 2010 Link to this post

    Hi, i am also using Radgrid2  inside the formtemplate of Radgrid1 .how to achieve insert/update/delete for the nested grid -Radgrid2.Please help me.

    Thanks
    Sree
  9. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 31 Mar 2010 Link to this post

    Hello Sree,

    Go through the forum thread below and see if it helps to achieve your goal:
    http://www.telerik.com/community/forums/aspnet-ajax/grid/nestedviewtemplate-example-question.aspx

    Regards,
    Pavlina
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017