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

Adding the RadGrid In the NodeTemplate Dynamically

2 Answers 188 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
santhosh
Top achievements
Rank 2
santhosh asked on 22 Jan 2009, 10:55 AM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2009, 01:12 PM
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.
0
Chrysa
Top achievements
Rank 1
answered on 27 Feb 2009, 03:50 PM
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
Tags
TreeView
Asked by
santhosh
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Chrysa
Top achievements
Rank 1
Share this question
or