How to bind inner grid of Hierarchy with Templates Grid

3 posts, 1 answers
  1. Amol
    Amol avatar
    57 posts
    Member since:
    Apr 2008

    Posted 27 May 2009 Link to this post

    Hi all,

    I have Grid / Hierarchy with Templates same as this. I want to bind grids on server side without using DataSourceID as in given e.g.

    Please suggest me that in which event should i bind inner grid ?
    Inner grid records are depends on its parent grid record.
    Inner grid has paging , sorting , group footer functionality.


    Thanks,
    Amol Wable
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2009 Link to this post

    Hello Amol,

    You can access the Nested Grid when a parent row is expanded in the PreRender event and set the datasource as shown in the code below:
    aspx:
     <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" OnPreRender="RadGrid1_PreRender" >   
            <MasterTableView DataSourceID="SqlDataSource1">        
               <NestedViewTemplate>            
                   <telerik:RadTabStrip runat="server" ID="TabStrip1" MultiPageID="Multipage1" SelectedIndex="0"
                    <Tabs> 
                      <telerik:RadTab runat="server" Text="Orders" PageViewID="PageView1"
                      </telerik:RadTab> 
                    </Tabs> 
                  </telerik:RadTabStrip> 
                  <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false"
                    <telerik:RadPageView runat="server" ID="PageView1"
     
                       <telerik:RadGrid runat="server" ID="RadGrid2"
                           <MasterTableView> 
                              ...... 
                           </MasterTableView> 
                       </telerik:RadGrid> 
     
                    </telerik:RadPageView> 
                  </telerik:RadMultiPage>  
           </NestedViewTemplate> 

    c#:
     protected void RadGrid1_PreRender(object sender, EventArgs e)  
        {  
      
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)  
            {  
                if (item.Expanded)  
                {  
      
                    foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView))  
                    {  
                        RadGrid grid = (RadGrid)item1.FindControl("RadGrid2");  
                        grid.DataSource = "  "//set the DataSource here 
                    }  
                }  
            }  
       }  

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Amol
    Amol avatar
    57 posts
    Member since:
    Apr 2008

    Posted 27 May 2009 Link to this post

    Hello Princy,

    Thanks for your quick reply,
    I have removed inner foreach loop from above PreRender function,
    it works fine.

     protected void rgJobLead_PreRender(object sender, EventArgs e) 
        { 
            JobLead objJobLead = new JobLead(); 
            foreach (GridDataItem item in rgJobLead.MasterTableView.Items) 
            { 
                if (item.Expanded) 
                { 
                    int JobLeadID = Convert.ToInt32(item["JobLeadID"].Text); 
                    GridNestedViewItem item1 = item.ChildItem; 
                    if (item1 != null
                    { 
                        RadGrid rgNotes = (RadGrid)item1.FindControl("rgNotes"); 
                        rgNotes.DataSource = objJobLead.GetJobLeadNotesByJobLeadID(JobLeadID); 
                        rgNotes.DataBind(); 
                    } 
                } 
            } 
        } 


    Thanks,
    Amol
Back to Top