NestedViewTemplate DataBinding

9 posts, 0 answers
  1. Robert
    Robert avatar
    23 posts
    Member since:
    Feb 2009

    Posted 08 Jul 2009 Link to this post

    I have a NestedViewTemplate which will contain several labels and another RadGrid. Because it's expensive to get the data for the labels and nested grid, I'd like to do this only when the NestedViewTemplate is visible.

    I set the HierarchyLoadMode to ServerOnDemand and registered for the ItemDataBoundEvent. In the ItemDataBound event, I check the ItemType, and if it's NestedView, I do my expensive data lookups and bind to the labels/grid.

    This works great, except that the NestedView items are being databound not when I expand the item in the grid, but instead when the grid is initially databound.

    What am I doing wrong?
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 10 Jul 2009 Link to this post

    Hello Robert,

    Indeed, you are correct in observing this behavior  - RadGrid does not support ServerOnDemand binding with NestedViewTemplate. When the ServerOnDemand mode is specified, then the main grid table reconstructs its items from the ViewState which means that the expanded item won't be databound. If the parent item is not databound, it follows that the nested view template related to it cannot be databound. For this reason, RadGrid always binds all of its nested view items on initial load except for the case demonstrated in the following online example: NestedViewTemplate Relations.

    I hope this helps.

    Best Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    23 posts
    Member since:
    Feb 2009

    Posted 10 Jul 2009 Link to this post

    If I wanted on-demand loading, how would I achieve this?
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 10 Jul 2009 Link to this post

    Hello Robert,

    Review the approach with NestedView template relations presented in the demo and modify your logic accordingly to take advantage of it and have load-on-demand mode for the expanded records. Otherwise consider the technique with dynamic panel visibility changing presented on this online demo of the product.

    Greetings,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 03 May 2011 Link to this post

    Hello,

    I'm using the method  "dynamic panel visibility changing presented on this online demo" as presented above.  The datasources are bound in the code behind page using the OnNeedDataSource event.  The problem I have is that OnNeedDataSource for the nested sub grids are not being fired until the Master grid is expanded once and then collapsed.

    So if the user expands the grid, then collapses it, then expands it again, we can see the grid with the data.  Nothing happens on the first expansion of the grid.

    At this point I'm not really sure what to do, so any adivce would be appreciated. 

    Thank you
  7. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 04 May 2011 Link to this post

    Hello Jack,

    When you use NeedDataSource to populate the nested grid, you might need to call rebind for it after it has been made visible. In other words, try calling Rebind() for the nested grid after you have set the panel's Visible property to true.

    This happens because when the grid is not initially visible, it does not bind automatically:
    http://www.telerik.com/help/aspnet-ajax/grid-visible-invisible-conventions.html

    Greetings,
    Tsvetina
    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.

  8. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 04 May 2011 Link to this post

    Thank you,  I thought that might be the case.

    I wound up implementing this :
    protected void grdCMT_ItemCommand(object source, GridCommandEventArgs e)
            {
                if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem && !e.Item.Expanded)
                {
                    RadAjaxPanel rpInnerPanel1;
                    rpInnerPanel1 = (RadAjaxPanel)((GridDataItem)e.Item).ChildItem.FindControl("InnerPanel1");
                    //RadAjaxPanel rpInnerPanel1 = (RadAjaxPanel)(e.Item.FindControl("InnerPanel1"));
                    rpInnerPanel1.Visible = true;
                    RadMultiPage rmMultiPage1 = (RadMultiPage)(rpInnerPanel1.FindControl("RadMultiPage1"));
                    RadPageView rpvInstalls = (RadPageView)(rmMultiPage1.FindControl("rpvInstalls"));
                    RadGrid rgInstalls = (RadGrid)(rpvInstalls.FindControl("rgrdInstalls"));
                    rgInstalls.Rebind();
                }
                else if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem && e.Item.Expanded)
                {
                    RadAjaxPanel rpInnerPanel1;
                    rpInnerPanel1 = (RadAjaxPanel)((GridDataItem)e.Item).ChildItem.FindControl("InnerPanel1");
                    rpInnerPanel1.Visible = false;
                }
            }

    It seems to work fine now,  I'm not sure if I needed to search through the child controls like that, but it works right now.

    Thank you
  9. Sridharan
    Sridharan avatar
    1 posts
    Member since:
    Jul 2014

    Posted 26 Jul 2014 in reply to Sebastian Link to this post

    I tried to control the on demand loading of radgrid inside nestedviewtemplate based on the code snippets in the demo. But the data binding still happens for radgrids inside the nestedviewtemplate along with master grid data.

    Here is my snippets of aspx
    ......
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" >
    <telerik:RadGrid ID="MasterGrid" datasourceid="master_table_ds" runat="server"
    AllowFilteringByColumn="True" AllowSorting="True" ClientSettings-ReorderColumnsOnClient="True"
    AllowPaging="True" PageSize="2" MasterTableView-AllowCustomSorting="True" AllowAutomaticUpdates="True"
    OnColumnCreated="RadGrid_ColumnCreated" OnItemDataBound="MasterGrid_ItemDataBound">

    <GroupingSettings CaseSensitive="false" />

    <MasterTableView DataKeyNames="ProjectID" EnableHeaderContextMenu="true"
    AutoGenerateColumns="false" HierarchyLoadMode="ServerOnDemand" ShowHeadersWhenNoRecords="false">

    ...
    ...
    <Columns>
    ...
    ..
    </Columns>
    ..
    <NestedViewTemplate>
    <asp:Panel ID="ProjectDetailsContainer" CssClass="viewWrap" Visible="false" runat="server">

    <div class="bgg-white-darkslategray" style="padding-left:10px; padding-top:8px; width:100%; overflow:auto;">
    ..
    ..
    <telerik:RadTabStrip runat="server" ID="Tabstrip" MultiPageID="tabPages" SelectedIndex="0">
    <Tabs>
    <telerik:RadTab Text="Project Info" PageViewID="PageView1" runat="server" >
    </telerik:RadTab>

    <telerik:RadTab Text="Roles" PageViewID="PageView2" runat="server">
    </telerik:RadTab>


     </Tabs>
    </telerik:RadTabStrip>


    <telerik:RadMultiPage runat="server" ID="tabPages" SelectedIndex="0" RenderSelectedPageOnly="false">
     
     
    <telerik:RadPageView ID="PageView1" runat="server" >
    <asp:Label ID="projectIDLabel1" Font-Bold="true" Font-Italic="true" Text='<%# Eval("ProjectID") %>'
    Visible="false" runat="server">
    </asp:Label>
    <telerik:RadGrid ID="ProjRecordDetailGrid" DataSourceID="detail_table1_ds" runat="server"  >
    ..
    ..


    <asp:ObjectDataSource ID="detail_table1_ds" SelectMethod="GetGridData" EnableCaching="true"
    OnSelecting="detail_table_ds_Selecting"  TypeName="dataSourceObject" CacheDuration="10" runat="server" >
    <SelectParameters>
    <asp:ControlParameter ControlID="projectIDLabel1" Name="ProjectID" Type="String" Direction="Input" />
      <asp:Parameter Name="datasource" DefaultValue="ProjectsForm" />
    </SelectParameters>
    </asp:ObjectDataSource>
     ..
    </telerik:RadPageView>
    </telerik:RadMultiPage>

    </div>
    </asp:Panel>
    </NestedViewTemplate>

     </MasterTableView>
     
    </telerik:RadGrid>
    </telerik:RadAjaxPanel>
    </div>

    -------------------------------------

    Code behind logic is similar to the one in demo

    Protected Sub MasterGrid_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles MasterGrid.PreRender

    If Not Page.IsPostBack Then

    MasterGrid.MasterTableView.Items(0).Expanded = True

    MasterGrid.MasterTableView.Items(0).ChildItem.FindControl("ProjectDetailsContainer").Visible = True

    End If

    End Sub



    Protected Sub MasterGrid_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles MasterGrid.ItemCommand

    If e.CommandName = RadGrid.ExpandCollapseCommandName And TypeOf e.Item Is GridDataItem Then

    DirectCast(e.Item, GridDataItem).ChildItem.FindControl("ProjectDetailsContainer").Visible = Not e.Item.Expanded

    End If

    End Sub



    Protected Sub MasterGrid_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles MasterGrid.ItemCreated

    If TypeOf e.Item Is GridNestedViewItem Then
     
    e.Item.FindControl("ProjectDetailsContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded


    End If

    End Sub

    ===================================

    Please advise if I am missing anything or doing anything incorrectly.

    thanks in advance,
    Sri

     

     
  10. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 30 Jul 2014 Link to this post

    Hello Sridharan,

    I'm sending a sample RadGrid web site to demonstrate optimal configuration of nested grid bindings. Please run the attached application and let me know if it helps you.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017