I have RadTreeView control inside a NestedViewTemplate of a RadGrid.
I want to reference this control in code behind so I can bind data to it, however I'm unsure of how to do this.
I was thinking it is something along this line:
Dim
RadTreeView1 As RadTreeView = CType(RadGrid2.MasterTableView.GetItems(GridItemType.NestedView.FindControl("RadTreeView1"), RadTreeView))
But this is incorrect. Can someone point me in the right direction
12 Answers, 1 is accepted
0
Hi Anthony,
I've made for you small application to illustrate you how to achieve this. You can find the project attached.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I've made for you small application to illustrate you how to achieve this. You can find the project attached.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

terrysmith
Top achievements
Rank 1
answered on 29 Jul 2008, 09:40 PM
I have an example almost identical to the above except that I have a label control in the NestedViewTemplate as follows:
<NestedViewTemplate>
<asp:Label ID="lblDetails" CssClass="Label" runat="server" />
</NestedViewTemplate>
However, e.Item.FindControl("lblDetails") returns Nothing for every row.
Am I missing something?
Thank you,
Terry
<NestedViewTemplate>
<asp:Label ID="lblDetails" CssClass="Label" runat="server" />
</NestedViewTemplate>
However, e.Item.FindControl("lblDetails") returns Nothing for every row.
Am I missing something?
Thank you,
Terry
0
Hello Terry,
Can you verify if this is inside if (e.Item is GridNestedViewItem)?
All the best,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Can you verify if this is inside if (e.Item is GridNestedViewItem)?
All the best,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

terrysmith
Top achievements
Rank 1
answered on 30 Jul 2008, 08:10 PM
Hello Vlad,
Within the ItemCreated event I can find the control if I look only for NestedViews like this:
...
ElseIf e.Item.ItemType = Telerik.Web.UI.GridItemType.NestedView Then
'This works.
Dim lblDetails As Label = e.Item.FindControl("lblDetails")
However, e.Item.DataItem is always Nothing inside the above block, so I can not bind the data to the label control.
How do I access the NestedView control(s) and the data at the same time?
Thank you,
Terry
Within the ItemCreated event I can find the control if I look only for NestedViews like this:
...
ElseIf e.Item.ItemType = Telerik.Web.UI.GridItemType.NestedView Then
'This works.
Dim lblDetails As Label = e.Item.FindControl("lblDetails")
However, e.Item.DataItem is always Nothing inside the above block, so I can not bind the data to the label control.
How do I access the NestedView control(s) and the data at the same time?
Thank you,
Terry
0

Vladimir
Top achievements
Rank 1
answered on 30 Jul 2008, 08:12 PM
Hi Terry,
Can you try ItemDataBound instead?
Vlad
Can you try ItemDataBound instead?
Vlad
0

terrysmith
Top achievements
Rank 1
answered on 30 Jul 2008, 08:32 PM
For ItemDataBound the code for NestedView item types never gets called:
Protected Sub gridEvents_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gridEvents.ItemDataBound
If e.Item.ItemType = Telerik.Web.UI.GridItemType.NestedView Then
'This line never gets hit.
Dim lblDetails As Label = e.Item.FindControl("lblDetails")
End If
End Sub
Protected Sub gridEvents_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gridEvents.ItemDataBound
If e.Item.ItemType = Telerik.Web.UI.GridItemType.NestedView Then
'This line never gets hit.
Dim lblDetails As Label = e.Item.FindControl("lblDetails")
End If
End Sub
0

Princy
Top achievements
Rank 2
answered on 31 Jul 2008, 10:44 AM
Hello TerrySmith,
You can probably try out the same code in the PreRender event as shown below.
cs:
Hope this helps.
Thanks
Princy.
You can probably try out the same code in the PreRender event as shown below.
cs:
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) |
{ |
Label lbl = (Label)item1.FindControl("Label1"); |
} |
} |
Thanks
Princy.
0

terrysmith
Top achievements
Rank 1
answered on 31 Jul 2008, 02:52 PM
Thanks,
On the first display of the Grid I can indeed use the PreRender event to bind the NestedView controls to the data. However, when I expand the NestedView in the Grid it posts back to the server.
First, it should not postback because it already has the data. I do not see any properties on the NestedViewTemplate declaration to prevent it from posting back. If the postback is the expected behavior, then I need to a way to know not to bind the NestedView data to every row in the Grid the first time.
The second problem is that on the second postback NeedDataSource gets called and brings back the same data it did the first time; however, when PreRender is called item.DataItem is Nothing for every GridNestedViewItem.
Thanks,
Terry
On the first display of the Grid I can indeed use the PreRender event to bind the NestedView controls to the data. However, when I expand the NestedView in the Grid it posts back to the server.
First, it should not postback because it already has the data. I do not see any properties on the NestedViewTemplate declaration to prevent it from posting back. If the postback is the expected behavior, then I need to a way to know not to bind the NestedView data to every row in the Grid the first time.
The second problem is that on the second postback NeedDataSource gets called and brings back the same data it did the first time; however, when PreRender is called item.DataItem is Nothing for every GridNestedViewItem.
Thanks,
Terry
0

terrysmith
Top achievements
Rank 1
answered on 01 Aug 2008, 02:12 PM
I'm still looking from some help on this one.
Thanks,
Terry
Thanks,
Terry
0
Hi Terry,
You can set MasterTableView's HierarchyLoadMode property to Client to avoid postback when an item is expanded.
Regarding ItemDataBound event not raised for NestedViewTemplate issue. Indeed this behavior can be observed in current version of the control. I'm happy to inform you though our developers has already addressed this issue. I'm attaching the latest internal trial build to this message. Feel free to submit a support request for the dev version of the build.
Sincerely yours,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can set MasterTableView's HierarchyLoadMode property to Client to avoid postback when an item is expanded.
Regarding ItemDataBound event not raised for NestedViewTemplate issue. Indeed this behavior can be observed in current version of the control. I'm happy to inform you though our developers has already addressed this issue. I'm attaching the latest internal trial build to this message. Feel free to submit a support request for the dev version of the build.
Sincerely yours,
Rosen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0

terrysmith
Top achievements
Rank 1
answered on 01 Aug 2008, 04:44 PM
Thank you!
You guys are great!
You guys are great!
0

Gayathri
Top achievements
Rank 1
answered on 23 Sep 2015, 09:04 AM
Thank you so much. it works fine.