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

NeedDataSource fired on InitInsert, Edit, Cancel and Update commands

3 Answers 374 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rogier Bestebroer
Top achievements
Rank 1
Rogier Bestebroer asked on 01 Apr 2010, 11:15 AM
Hi,

I encounter the following strange behaviour when using the Telerik RadGrid.

I have a 3-tiered hierarchical RadGrid. Simplified:
<RadGrid>
<NestedViewTemplate>
<RadGrid>
<NestedViewTemplate>
<RadGrid>
</RadGrid>
</NestedViewTemplate>
</RadGrid>
</NestedViewTemplate>
<RadGrid>

The HierarchyLoadMode is set to "ServerOnDemand" (default?), and all data is wired using the NeedDataSource event. The EditForm is set to a WebUserControl.

This construction however poses two significant problems:

  1. When a parent grid item is expanding, the parent's NeedDataSource event is called, while it isn't specifically needed for the parent to rebind. In fact, if I check the GridRebindReason property and make it so it doesn't set the DataSource property when the reason is GridRebindReason.DetailTableBinding, it works perfectly. So if the parent isnt required to rebind, why does it call the eventhandler? It reduces the amount of database querying by a lot if I filter for the DetailTableBinding flag.
  2. Even more "disturbing": When I try to edit or add any item, in the parent grid or either of the childgrids, the NeedDataSource event is called for every RadGrid in the hierarchy. Which results in a lot of queries for radgrids that aren't even visible on the page.

Is this a known problem? And more importantly, is there any way around this? I'd attach the code but sadly I don't have a clean version of the page.

Above problems are encountered using ASP.NET 3.5, C#, and the ASP.NET AJAX toolkit Q1 2010

Greetings

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 07 Apr 2010, 09:58 AM
Hi Rogier,

I followed your scenario in the attached project and here are my findings:
    - With NestedViewTemplate, despite the HierarchyLoadMode, all the grid data is loaded at once, either the master table view items and the nested view ones.
    - Regarding the NeedDataSource event of the most outter grid firing, I was able to replicate it and will forward this issue for further investigation to our developers.
    - I was not able to replicate the problem described in point 2. of your post. Can you check the sample attached to this post and let me know what differs in your case?

Best wishes,
Iana
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
Rogier Bestebroer
Top achievements
Rank 1
answered on 16 Apr 2010, 04:15 PM
Hi Lana,

Thank you for looking into this for me. I've taken a look at your example, here are my conclusions:

  • When I put AutoGenerateEditColumn to true, and I click it, I am able to confirm my second point. When bringing up the edit window for any of the parent GridItems the following happens:
  1. The ItemCommand event is called for the corresponding parent GridItem (obviously).
  2. The NeedDataSource event is called for the parent RadGrid (not sure why though, because theres no actual databinding going on)
  3. The NeedDataSource event is called for all 5 of the subgrids (there really is no reason why though).

Once again, the above happens when opening/closing an edit/insert "form". Set AutoGenerateEditColumn to true to reproduce the problem.

Additionally, I managed to "fix" the first issue (first post) by adding the following line in the NeedDataSource eventhandler:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e) 
    if (e.RebindReason.HasFlag(GridRebindReason.DetailTableBinding)) 
        return
 
    // Fetch the data 
 
public static class EnumExtensions 
    public static bool HasFlag(this Enum input, Enum matchTo) 
    { 
        return (Convert.ToUInt32(input) & Convert.ToUInt32(matchTo)) != 0; 
    } 
 

HasFlag is an extension method which checks if a flag is present.

Greetings
0
Accepted
Iana Tsolova
Telerik team
answered on 19 Apr 2010, 02:27 PM
Hi Rogier,

The order of firing of the events when you click on the edit button for a parent grid items is proper and the events are fired properly. You can check this article for more information on RadGrid events sequence.

And I will try clarifying on why the nested grids NeedDataSource is fired in this case: The NestedViewTemplate hierarchy is designed for cases where you want to avoid showing grid with multiple columns but add a few columns in the grid master table view only and display the additional information for the same database record in the NestedViewTemplate. Therefore when the grid items are bound the NestedViewItems controls are bound as well. And that is why the grids in the NestedViewTemplate NeedDataSource event is fired.

To overcome that behavior, you try modifying the inner grid NeedDataSource as below and see if it works for you. Or you can define standard hierarchical grid with DetailTables instead.

protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    if (e.RebindReason != GridRebindReason.InitialLoad)
    {
        //bind the grid here
    }
}


Sincerely yours,
Iana
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
Rogier Bestebroer
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Rogier Bestebroer
Top achievements
Rank 1
Share this question
or