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

Nested RadGrid updating all internal records

7 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sal
Top achievements
Rank 1
Sal asked on 21 Jul 2011, 08:39 PM
I have a grid which is populated from a webservice with the required data. I then have a nested template where I show, inside a FormView, further details for the partiular record I selected to expand. I created an object data source for this, which ultimately also talks to a web service to retreive the data.  

It works fine for individual records retrieved one at a time, however, when I try to expand two records at the same time, both "views" are updated with the exact same information, instead of keeping the details for each record independently.

I think I know that this happens because it refreshes the datasource everytime I select a new record to expand. The problem is that I don't know how to tell the grid (and therefore the nested formview) not to refresh all open windows but only the one expanded.

Here is an excerpt from my code:

<telerik:RadGrid ID="OrbitRadGrid" runat="server" AllowFilteringByColumn="True" AllowSorting="True" VirtualItemCount="50000" 
        GridLines="None" AllowPaging="true" PageSize="30" AllowCustomPaging="true" ShowGroupPanel="false" EnableLinqExpressions="false" 
        OnNeedDataSource="OrbitRadGrid_NeedDataSource" OnSortCommand="OrbitRadGrid_SortCommand" 
        Skin="WebBlue" >
  
        <ClientSettings AllowColumnsReorder="True" AllowDragToGroup="False" ReorderColumnsOnClient="True">
            <Scrolling AllowScroll="True" EnableVirtualScrollPaging="True" UseStaticHeaders="True" SaveScrollPosition="True" />
            <Resizing AllowColumnResize="True" />
        </ClientSettings>
  
        <MasterTableView DataKeyNames="Item_Name, Source_Name" AutoGenerateColumns="False" AllowNaturalSort="false">
              
            <Columns>
                <telerik:GridBoundColumn DataField="Item_Name" HeaderText="Item Name" 
                    ReadOnly="True" SortExpression="Item_Name" UniqueName="Item_Name" HeaderStyle-Width="220px">
                </telerik:GridBoundColumn>
  
                <telerik:GridBoundColumn DataField="Source_Name" HeaderText="Item Source" ReadOnly="True" 
                    SortExpression="Source_Name" UniqueName="Source_Name" HeaderStyle-Width="220px">
                </telerik:GridBoundColumn>
  
                <telerik:GridBoundColumn DataField="ItemType_Name" HeaderText="Item Type" ReadOnly="True" 
                    SortExpression="ItemType_Name" UniqueName="ItemType_Name" HeaderStyle-Width="115px">
                </telerik:GridBoundColumn>
  
                <telerik:GridBoundColumn DataField="Team_Name" HeaderText="Item Team" ReadOnly="True" 
                    SortExpression="Team_Name" UniqueName="Team_Name" HeaderStyle-Width="115px">
                </telerik:GridBoundColumn>
  
                <telerik:GridBoundColumn DataField="IsTestItem" HeaderText="Test" ReadOnly="True" 
                    UniqueName="IsTestItem"  AllowFiltering="false" HeaderStyle-Width="50px">
                </telerik:GridBoundColumn>
                  
                <telerik:GridBoundColumn DataField="IsItemOnHold" HeaderText="On Hold" ReadOnly="True" 
                    UniqueName="IsItemOnHold"  AllowFiltering="false" HeaderStyle-Width="62px">
                </telerik:GridBoundColumn>
                 
            </Columns>
          
            <NestedViewSettings DataSourceID="MasterItemsDetails" >
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="ItemName" MasterKeyField="Item_Name" />
                    <telerik:GridRelationFields DetailKeyField="ItemSource" MasterKeyField="Source_Name" />
                </ParentTableRelation>
            </NestedViewSettings>
  
            <NestedViewTemplate>
                <asp:FormView ID="FormView" runat="server" DataSourceID="MasterItemsDetails">
                    <ItemTemplate>
                        <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
                            <div class="contactWrap">
                                <table>
                                    <tr>
                                        <td>
                                            <fieldset style="padding: 10px;">
                                                <legend style="padding: 5px;"><b>General info</b></legend>
                                                <table width="400">
                                                    ...
                                                </table>
                                            </fieldset>
                                        </td>
                                        <td>
                                            <table width="200">
                                                <tr>
                                                    <td>
                                                        <fieldset style="padding: 10px;">
                                                            <legend style="padding: 5px;"><b>Status</b></legend>
                                                            <table>
                                                                ...
                                                            </table>
                                                        </fieldset>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <fieldset style="padding: 10px;" >
                                                            <legend style="padding: 5px;"><b>Coverage</b></legend>
                                                            <table>
                                                                ...
                                                            </table>
                                                        </fieldset>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                        <td>
                                            <fieldset style="padding: 10px;" >
                                                <legend style="padding: 5px;"><b>Rejection Information</b></legend>
                                                <table width="300">
                                                    ...
                                                </table>
                                            </fieldset>
                                        </td>
  
                                    </tr>
                                </table>
                            </div>
                        </asp:Panel>
                    </ItemTemplate>             
                </asp:FormView>
            </NestedViewTemplate>
   
        </MasterTableView>
  
        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
  
    </telerik:RadGrid>
  
    <asp:ObjectDataSource runat="server" ID="MasterItemsDetails" SelectMethod="Get" TypeName="Orbit3UI.Model.MasterItemDetailsDataSource">
        <SelectParameters>
            <asp:Parameter Name="itemName" Type="String" />
            <asp:Parameter Name="itemSource" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>

The OnNeedDataSource event is used for filtering of the Master table. 

Is there anything I need to set in order to prevent the nested formviews to update with each request?

Thank you
 

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 Jul 2011, 12:48 PM
Hi Sten,

I reviewed the provided code, and it looks correct. Can you please elaborate how exactly you expand the two records at the same time? It will be best if you can send us a sample project via support ticket, where the described problem can be observed. Thus we will be able to debug it locally and provide a solution/fix. 

Best wishes,
Pavlina
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.

0
Sal
Top achievements
Rank 1
answered on 27 Jul 2011, 04:26 PM
Hi Pavlina and thank you for your reply.

In order to expand the two records I just click on the arrow left of the row (as it to display a nested grid, except that I used a template to show just a view of the particular record).

When the expansion is to be performed, the code behind goes to the ObjectDataSource and executes the Get method (refer to the code), which, by means of a WCF webservice, gets the detailed data for the particular record I selected, from a sql server database.
 
For example, if I have a radGrid, from which I already expanded record 1 in the mater table (pardon the text example):

Name, Source, Type
-----------------------------
> name1, source1, type1
       --- Detailed View for record1
            including lots of information about it
> name2, source2, type2
> name3, source3, type3   
> name4, source4, type4   

and then  want to expand another record  (lets say record3) without closing the first one, the grid will obviously go the Get method from the ObjectDataSource to get the data via a WCF service and retrieve the new set of details from the database, I would then, expect to see the following:

Name, Source, Type
-----------------------------
> name1, source1, type1
       --- Detailed View for record1
            including lots of information about it
> name2, source2, type2
> name3, source3, type3   
       --- Detailed View for record3 
            including lots of information about it
> name4, source4, type4   

In which case both expanded records should have their own detail data , instead, both expanded views are updated with the details for record3!, effectively wiping out the information I had for record1. Visualy:

Name, Source, Type
-----------------------------
> name1, source1, type1
       --- Detailed View for record3 
            including lots of information about it
> name2, source2, type2
> name3, source3, type3   
       --- Detailed View for record3 
            including lots of information about it
> name4, source4, type4   

Unfortunately, our internal website application is big and does connections to databases and webservices and such which would not allow you to debug it even if I sent you the whole solution.  

Thank you.

Sal


0
Sal
Top achievements
Rank 1
answered on 28 Jul 2011, 03:28 PM
Here is additional info. If I set the LoadHierarchyMode="ServerBind", it does preserve the values correctly. This makes sense as the server already loaded the whole grid detailed views and will be just showing them (as they are saved all in the view state).

Now, if I set the LoadHierarchyMode="ServerOnDemand" it seems like the view state is not preserved as it does update all the visible records to the last value retrieved from the database. It ceratainly does not seem like it is a bug as your demos do not display the behavior so, what then?

I cannot use ServerBind since this takes a very long time to process, I just want it to load the items as I demand it and preserve the ones that are visible already!

Have been reading all info i found on nested view templates and also seen several of your demos (using or not the viewtemplate) and still don't know what the issue is.

So what do I have to do? 
0
Sal
Top achievements
Rank 1
answered on 28 Jul 2011, 03:28 PM
Here is additional info. If I set the LoadHierarchyMode="ServerBind", it does preserve the values correctly. This makes sense as the server already loaded the whole grid detailed views and will be just showing them (as they are saved all in the view state).

Now, if I set the LoadHierarchyMode="ServerOnDemand" it seems like the view state is not preserved as it does update all the visible records to the last value retrieved from the database. It ceratainly does not seem like it is a bug as your demos do not display the behavior so, what then?

I cannot use ServerBind since this takes a very long time to process, I just want it to load the items as I demand it and preserve the ones that are visible already!

Have been reading all info i found on nested view templates and also seen several of your demos (using or not the viewtemplate) and still don't know what the issue is.

So what do I have to do? 
0
Sal
Top achievements
Rank 1
answered on 28 Jul 2011, 07:35 PM
I found the solution to the problem.

There seems to be a difference in which radGrid hierarchy is handled when using ObjectDataSources as opposed to SqlDataSources. For whatever reason the mapping in the NestedVewSettings is not correctly communicated to the nested template view and therefore, the last record expanded is used to update ALL currently expanded views. This is plain wrong since both data sources should behave the same or pretty much the same, at least in this particular case.

The solution is simple, take a look at the following post where the example code says it all.

http://www.telerik.com/community/forums/aspnet-ajax/grid/master-detail-hierarchy-binding-via-objectdatasource.aspx#1030578

In summary, this is what I had to do:

Removed the Nested View Settings:

<NestedViewSettings DataSourceID="MasterItemsDetails" >
        <ParentTableRelation>
            <telerik:GridRelationFields DetailKeyField="ItemName" MasterKeyField="Item_Name" />
            <telerik:GridRelationFields DetailKeyField="ItemSource" MasterKeyField="Source_Name" />
        </ParentTableRelation>
</NestedViewSettings>

In the NestedViewTemplate, added a couple of hidden lables representing the paramenters that the ObjectDataSource Method takes. These parameters are going to be extracted from the Master Table, i.e. they represent the master keys to that table. 
Also, moved the objectdatasource to the template as well but this time the SelectParamters are not delcared as asp:Parameter but asp:ControlParameter and made sure it mapped the Name to the detail keys .

<NestedViewTemplate>
                <asp:Label ID="ItemName"   Text='<%# Eval("Item_Name") %>'   Visible="false" runat="server" />
                <asp:Label ID="ItemSource" Text='<%# Eval("Source_Name") %>' Visible="false" runat="server" />
                <asp:FormView ID="FormView" runat="server" DataSourceID="MasterItemsDetails">
                    <ItemTemplate>
                                    ...
                                    ...
                </asp:FormView>
  
               <asp:ObjectDataSource runat="server" ID="MasterItemsDetails" SelectMethod="Get"           
                                                         TypeName="Orbit3UI.Model.MasterItemDetailsDataSource">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ItemName" Name="ItemName" PropertyName="Text" />
                        <asp:ControlParameter ControlID="ItemSource" Name="ItemSource" PropertyName="Text" />
                    </SelectParameters>
                </asp:ObjectDataSource>
              
 </NestedViewTemplate>

That's it. It worked! I hope it helps someone else. I searched for some time before finding the solution, hopefully you won't have to.

Sal.
0
Pavlina
Telerik team
answered on 01 Aug 2011, 03:30 PM
Hi Sal,

Thank you for sharing your solution with the community - thus you can help other community members who are trying to implement similar functionality.

Regards,
Pavlina
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.

0
Sal
Top achievements
Rank 1
answered on 08 Aug 2011, 02:14 PM
I acutally had other issues, but they are solved by moving the datasource before the formview, for details see the last post in the following thread. Once again, thanks to Radoslav for the answer!

http://www.telerik.com/community/forums/aspnet-ajax/grid/master-detail-hierarchy-binding-via-objectdatasource.aspx
Tags
Grid
Asked by
Sal
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Sal
Top achievements
Rank 1
Share this question
or