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

Reference control in NestedViewTemplate

12 Answers 258 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 07 Jun 2008, 05:37 PM

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

Sort by
0
Vlad
Telerik team
answered on 10 Jun 2008, 08:02 AM
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
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
0
Vlad
Telerik team
answered on 30 Jul 2008, 05:31 AM
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.
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
0
Vladimir
Top achievements
Rank 1
answered on 30 Jul 2008, 08:12 PM
Hi Terry,

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
0
Princy
Top achievements
Rank 1
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:
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {         
      foreach (GridNestedViewItem item1 in RadGrid1.MasterTableView.GetItems(GridItemType.NestedView)) 
            { 
                Label lbl = (Label)item1.FindControl("Label1");              
            } 
    } 
         
Hope this helps.

Thanks
Princy.

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
0
Rosen
Telerik team
answered on 01 Aug 2008, 03:20 PM
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.
0
terrysmith
Top achievements
Rank 1
answered on 01 Aug 2008, 04:44 PM
Thank you!

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.
Tags
Grid
Asked by
Anthony
Top achievements
Rank 1
Answers by
Vlad
Telerik team
terrysmith
Top achievements
Rank 1
Vladimir
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Rosen
Telerik team
Gayathri
Top achievements
Rank 1
Share this question
or