I have a RadTreeView which binds to a HierarchicalDataSource fine, and I can instantiate a template for the node OK too. The template consists of a RadAjaxPanel that contains an ASCX user control. This all works fine too. My problem is I want to databind a Label web control in the templates' user control to the Content field of the dataitem for each node.
Because the dataitem is only available in the NodeDataBound handler, I reckon I need to get a reference to the Label in the NodeDataBound handler. The problem is, the NodeTemplate property is 'Nothing' when I examine the properties of e.Node from the event arguments. Therefore I don't think I can get a reference to controls in the template at this stage.
Can someone advise, how should I get a reference to the node template at the same time as I can get to the nodes DataItem - the two never seem to be populated at the same time.
Thanks if you can help.
Regards
7 Answers, 1 is accepted
Here is a sample demo project that shows how you can get the DataItem in the NodeTemplate.
All the best, Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Thanks for getting back to me, but unfortunately I think there is a misunderstanding with my question. I can access DataItem fine in the NodeDatabound handler, in the way demonstrated in the example you provide - however, as I mentioned before, what I am struggling to work out is how to get a reference into the controls of the ASCX based node template, in that same NodeDatabound handler. The example you provide just demonstrates the basic example of creating Label objects in the InstantiateIn method. I am wondering what is the recommended technique for databinding the DataItem contents into a Label defined in the ASCX control that I am using for the template. Currently, the NodeTemplate property appears to be empty in the NodeDatabound handler. Is NodeTemplate supposed to be Nothing in this handler? The template appears to be instantiated OK, it is used in the rendering of each RadTreeNode, it's just that I cannot databind individual Label controls in the ASCX control. I reckon the best way would be, in the NodeDataBound handler, to access my DataItem object (e.Node.DataItem), no problem here, but then how to get a reference to the Template controls in this handler, to then set the Text property etc. for template controls:
Foobar example:
FoobarLabel.Text = e.Node.DataItem.Content
The right side of this works for me already OK, I have a custom data object with String properties, BUT ... for the left side, how do I find the Label control if I cannot get a reference to the node template in NodeDatabound.
Thanks for any advice.
Regards
If I understood you correctly, you want to bind a NodeTemplate which is in the ASPX page-here is the modified project.
If you are trying to get the NodeTemplate in the NodeBataBound event you can do it with RadTreeView1.NodeTemplate (in this example) because the e.Node. NodeTemplate is actually the Per-Node Template, but in this case there are no Per-Node Templates.
All the best, Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Thanks, that makes sense, but what is the recommended technique for accessing the contents of the per-node template in that case? In the end, I just had to use a rather clumsy Find process in the NodeDataBound handler, that depended on my providing the type I was looking for:
For Each ctrl1 As Control In e.Node.Controls
If ctrl1.GetType.ToString = "Telerik.Web.UI.RadAjaxPanel" Then
For Each ctrl2 As Control In ctrl1.Controls
If ctrl2.GetType.ToString = "ASP.MyFooBarCommentUserControlType" Then
currentUC = CType(ctrl2, ASP.MyFooBarCommentUserControlType)
End If
Next
End If
Next
But this seemed a bit inelegant, so I am wondering if the controls within per-node templates cannot be accessed in a more efficient way.
Thanks very much if you can advise.
Regards
Unfortunately the per-node templates are not available in the NodeDateBound.
You can have a look at our ASPX Template Structure help topic for more information about them.
Greetings,
Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
It truly looks like a limitation of the template usage and that is why i sent you the link that explains what exactly is the usage of the per-node template and the when the nodes are generated one can only use the Global ones.
Greetings,
Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.