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

NeedDataSource not firing for NestedViewTemplate Grid initially

10 Answers 615 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Beal
Top achievements
Rank 1
Adam Beal asked on 21 Jan 2010, 12:05 AM
I have a very strange thing happening and really need some help. I am running the code below which includes a parent radgrid and a nested one but when the page first loads and I expand one of the top level grid items then the nestedviewtemplate grid (detailsGrid) doesn't have any data in it. When debugging this the detailsGrid_OnNeedDataSource event is not firing. However the parent grid (destinationCodesGrid) destinationCodesGrid_OnNeedDataSource method is firing immediately then the page renders with nothing in the nested grid. About 20 seconds later the detailsGrid_OnNeedDataSource event fires and the breakpoint hits but only after it is too late.

Here is an odd thing though if I do some other action in the grid that fires a postback first such as paging to the next page or clicking edit then after that point the destinationCodesGrid_OnNeedDataSource method fires immediately. Please advise!

Here is the code:

====ASPX========

 

     <telerik:RadGrid ID="destinationCodesGrid" runat="server" AutoGenerateColumns="False"   
                    OnInsertCommand="destinationCodesGrid_OnInsertCommand" 
                    OnUpdateCommand="destinationCodesGrid_OnUpdateCommand"                    
                    OnNeedDataSource="destinationCodesGrid_OnNeedDataSource" 
                    OnDeleteCommand="destinationCodesGrid_OnDeleteCommand" 
                 OnItemCreated="destinationCodesGrid_OnItemCreated" 
                     OnItemCommand="destinationCodesGrid_OnItemCommand" 
                    Width="500px"   
                    AutoGenerateDeleteColumn="True"   
                    OnColumnCreated="destinationCodesGrid_OnColumnCreated" AllowFilteringByColumn="True"   
                    GridLines="None" AllowPaging="true" PageSize="10"   
                     > 
                    <HeaderContextMenu> 
                        <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
                    </HeaderContextMenu> 
                    <MasterTableView DataKeyNames="DialID" EditMode="InPlace" InsertItemDisplay="Bottom" 
                        CommandItemDisplay="Bottom">  
                          
                <NestedViewTemplate>          
                 
                                <telerik:RadGrid runat="server" ID="detailsGrid" OnNeedDataSource="detailsGrid_OnNeedDataSource"   
                                    ShowFooter="true" AllowSorting="true" AutoGenerateDeleteColumn="True">  
                                    <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="false" 
                                        DataKeyNames="UniqueKey" > 
                                         
                                        <Columns> 
                                            <telerik:GridBoundColumn DataField="PhoneNum" HeaderText="Phone Number" UniqueName="PhoneNum">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="DestName" HeaderText="Destination Name" UniqueName="DestName">  
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridEditCommandColumn /> 
                                        </Columns> 
                                    </MasterTableView> 
                                </telerik:RadGrid>                                                    
                   
                </NestedViewTemplate> 

======Code behind=======

 

protected void Page_Load(object sender, EventArgs e)   
{  
}    
 
  protected void destinationCodesGrid_OnNeedDataSource(object source, GridNeedDataSourceEventArgs e)  
{  
        Administration admin = new Administration(CurrentServer);  
        destinationCodesGrid.DataSource = admin.RetrieveSpeedDialMaster();  
}  
 
 
protected void detailsGrid_OnNeedDataSource(object source, GridNeedDataSourceEventArgs e)  
{  
        RadGrid grid = (RadGrid)source;  
        GridNestedViewItem nestedItem = (GridNestedViewItem)grid.NamingContainer;  
        string dataKeyValue = Convert.ToString(((GridDataItem)(nestedItem.ParentItem)).GetDataKeyValue("DialID"));   
        RadGrid tempGrid = (RadGrid)nestedItem.FindControl("detailsGrid");  
        tempGrid.DataSource = GetDetailsDataSource(dataKeyValue);  

10 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 21 Jan 2010, 06:11 PM
I really need some help on this if you guys don't mind. Basically the OnNeedDataSource event for the nested radgrid is firing but most of the time about 20 seconds after the page is done loading :(
0
Radoslav
Telerik team
answered on 26 Jan 2010, 09:11 AM
Hello Adam,

Initially when the items of the parent RadGrid are collapsed the child grids are not visible. So when you expand the first item of the parent RadGrid the child RadGrid initially in not visible and its  NeedDataSource event is not fired. To achieve the desired functionality you need to call Rebind() method manually. You could do this in ItemCommand event handler of the parent RadGrid. When the RadGrid's item is expanded you could call Rebind() method on the details RadGrid:
void destinationCodesGrid_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName)
    {
        GridDataItem item = e.Item as GridDataItem;
        if (!item.Expanded)
        {
            GridNestedViewItem nestedItem = (GridNestedViewItem)item.ChildItem;
            string dataKeyValue = Convert.ToString(((GridDataItem)(nestedItem.ParentItem)).GetDataKeyValue("DialID"));
            RadGrid tempGrid = (RadGrid)nestedItem.FindControl("detailsGrid");
            tempGrid.Rebind();
 
        }
    }
}

Additionally I am sending you a simple example which illustrates how to achieve the desired scenario.
I hope this helps.

All the best,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Paul
Top achievements
Rank 1
answered on 20 Jul 2010, 12:48 PM
I have the exact same problem

Following the sample provided by Telerik I managed to get the detailsgrid_oneeddatasource to fire:

BUT the detailsgrid does not display any data, You simply get "no records to display". I know the datasource has records in it.

Just once, I'd like Telerik sample code to work the way it claims to!

Just once, I'd like someone from Telerik to respond to questions. A productivity tool is not productive when you have to spend days looking for hacks.

0
Radoslav
Telerik team
answered on 23 Jul 2010, 07:17 AM
Hello Paul,

Based on the provided information is hard to determine what is causing this unwanted behavior. To offer a solution we need you to send us a simple running project with which we can reproduce the issue. Could you please send us a simple runnable example demonstrating the problem. You could open a formal support ticket from your Telerik account and attach a ZIP file there. In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

Greetings,
Radoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 23 Jul 2010, 08:56 AM
Thanks for the reply, but I have decided not to continue trialling the Telerik toolset.

I have simply had too many problems with it.
0
Sebastian
Telerik team
answered on 23 Jul 2010, 09:00 AM
Hello Paul,

We are sorry to hear that and would gladly answer any additional questions you may have if you decide to try our AJAX controls in the future.

Kind regards,
Sebastian
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stacy
Top achievements
Rank 1
answered on 24 Aug 2010, 04:04 PM
I have a similar problem to this, although I am getting the inner grid to fire the need data source event on initial load and my data is coming back inside it fine.  My problem is when I need to add a new record to inner grid. The nested view collapses and I am unable to add a new record or update existing records inside my inner grid.  If anyone has done this successfully I would appreciate some help.  I am also submitting a support ticket to Telerik but hoping another person out there has done this and can provide an answer.

Thanks!
0
Bodevain Svensson
Top achievements
Rank 1
answered on 27 Aug 2010, 09:46 AM
If you do not rebind explicitly the outer grid, the nested view should not be collapsed when you add a new item or update an existing item. In case you need to rebind the hosting grid on such operation, I would recommend you to persist the expanded states of the items in the way described in this code library post.

Bodevain
 
0
Trevor
Top achievements
Rank 1
answered on 27 Jan 2016, 01:23 PM

Oddly  I have a diff problem but related..

When the main grid opens.. ALL the unexpanded need data source events fire.. causing painfully slow display..

 

Why are the second undexpanded needatasource events firing?  IS there a setting I am missing

0
Eyup
Telerik team
answered on 01 Feb 2016, 12:15 PM
Hello Trevor,

To achieve this requirement, you can wrap the inner grid within an invisible panel container. Then, you can enable its Visible property when its corresponding parent item is expanded:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/hierarchy-with-templates/defaultcs.aspx

I am also sending a sample RadGrid web site to demonstrate a practical implementation with programmatic binding of the grids.

Regards,
Eyup
the Telerik team
 
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
 
Tags
Grid
Asked by
Adam Beal
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Radoslav
Telerik team
Paul
Top achievements
Rank 1
Sebastian
Telerik team
Stacy
Top achievements
Rank 1
Bodevain Svensson
Top achievements
Rank 1
Trevor
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or