Reference control in NestedViewTemplate

13 posts, 0 answers
  1. Anthony
    Anthony avatar
    11 posts
    Member since:
    Sep 2007

    Posted 07 Jun 2008 Link to this post

    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

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Jun 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. terrysmith
    terrysmith avatar
    127 posts
    Member since:
    Nov 2006

    Posted 29 Jul 2008 Link to this post

    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
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 30 Jul 2008 Link to this post

    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.
  6. terrysmith
    terrysmith avatar
    127 posts
    Member since:
    Nov 2006

    Posted 30 Jul 2008 Link to this post

    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
  7. Vlad
    Vlad avatar
    115 posts
    Member since:
    Dec 2007

    Posted 30 Jul 2008 Link to this post

    Hi Terry,

    Can you try ItemDataBound instead?

    Vlad
  8. terrysmith
    terrysmith avatar
    127 posts
    Member since:
    Nov 2006

    Posted 30 Jul 2008 Link to this post

    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
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Jul 2008 Link to this post

    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.

  10. terrysmith
    terrysmith avatar
    127 posts
    Member since:
    Nov 2006

    Posted 01 Aug 2008 Link to this post

    I'm still looking from some help on this one.

    Thanks,
    Terry
  11. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 01 Aug 2008 Link to this post

    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.
  12. terrysmith
    terrysmith avatar
    127 posts
    Member since:
    Nov 2006

    Posted 01 Aug 2008 Link to this post

    Thank you!

    You guys are great!

  13. Gayathri
    Gayathri avatar
    25 posts
    Member since:
    Oct 2014

    Posted 23 Sep 2015 in reply to Vlad Link to this post

    Thank you so much. it works fine.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017