Adding the RadGrid In the NodeTemplate Dynamically

3 posts, 0 answers
  1. santhosh
    santhosh avatar
    35 posts
    Member since:
    Oct 2008

    Posted 22 Jan 2009 Link to this post

    Hi,

    I want to add the radgrid to the treeview dynamically, kindly advise how to add radgrid dynamically to tree view using NodeTemplate.


    Regards,

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

    Posted 22 Jan 2009 Link to this post

    Hi Santhosh,

    Try the following code snippet for adding RadGrid to RadTreeView as NodeTemplate. In this example I tried to pass the DataSourceID as parameter when creating the template node.

    CS:
    protected override void OnInit(EventArgs e) 
        RadTreeView1.NodeTemplate = new RadGridTemplate(); 
        base.OnInit(e); 
    protected void Page_Load(object sender, EventArgs e) 
        if (!Page.IsPostBack) 
        { 
            RadTreeView1.FindNodeByText("Node1").Nodes.Add(new RadTreeNode("SqlDataSource1")); 
        } 
        RadTreeView1.DataBind(); 
    class RadGridTemplate : ITemplate 
        public void InstantiateIn(Control container) 
        { 
            RadGrid RadGrid1 = new RadGrid(); 
            RadGrid1.DataBinding += new EventHandler(RadGrid_DataBinding); 
            container.Controls.Add(RadGrid1); 
        } 
        private void RadGrid_DataBinding(object sender, EventArgs e) 
        { 
            RadGrid target = (RadGrid)sender; 
            RadTreeNode node = (RadTreeNode)target.BindingContainer; 
            string source = (string)DataBinder.Eval(node, "Text"); 
            target.DataSourceID = source; 
        } 

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" Runat="server"
    <Nodes> 
          <telerik:RadTreeNode Text="Node1"></telerik:RadTreeNode> 
    </Nodes>       
    </telerik:RadTreeView> 

    Thanks,
    Shinu.
  3. Chrysa
    Chrysa avatar
    12 posts
    Member since:
    Jan 2009

    Posted 27 Feb 2009 Link to this post

    Hi Shinu:
    Does this work when the data source is relational data?  I have 5 relational tables nested one to the other... I followed the telerik relational data training video exactly - and it works wonderfully, but it would be really good to put a grid in at each node level...
    Thanks,
    Chrysa
Back to Top