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

DetailTable within NestedViewTemplate

5 Answers 271 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Wood
Top achievements
Rank 1
Paul Wood asked on 29 Jan 2009, 12:10 AM
I am attempting to add a customised DetailTable to my RadGrid, but can't seem to get it working. I have tried two approaches so far with no luck.

1. Use another RadGrid within a NestedViewTemplate. The problem with this is hooking up the Parent/Child Relationship - I can't seem to get this happening properly as when you expand the row SelectedIndexChanged isn't fired. Any ideas?
2. Use a DetailTable alongside/inside a NestedViewTemplate. I could only get one or the other working, don't think this is possible.

Therefore, how am I supposed to show a DetailTable with extra stuff around it (basically some more data bound fields from the parent record that isn't shown in the row itself)?

Surely this would be functionality that is used quite frequently but I can't seem to find a demo or forum post exactly addressing this.

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 02 Feb 2009, 01:08 PM
Hello Paul,

Attached to this message, is a small example, which handles a similar task.
I hope it helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul Wood
Top achievements
Rank 1
answered on 12 Feb 2009, 04:51 AM
Thanks for the example, but it doesn't quite match my requirements as I can't use the DetailTable functionality due to the nature of my detail 'view'. Somehow I need to setup the parent / child relationship between the parent RadGrid and the RadGrid within the NestedViewTemplate. The only way I've been able to do this is to set the DefaultValue of the child's sqlDataSource parentID parameter on DataBinding the child grid. The problem with this though is of course as soon as you add or edit an item in the child grid, all parent row's child grids rebind with the final row's parentID.

Here is a cut down version of the nestedviewtemplate of my parent RadGrid so you can see what I mean.

      <NestedViewTemplate>
        <fieldset>
          <legend>Description</legend>
          <asp:Literal ID="ltlDescription" runat="server" Text='<%#Eval("Description")%>' />
          <asp:Literal ID="ltlWorkInProgressID" runat="server" Text='<%#Eval("WorkInProgressID")%>' Visible="false" />
        </fieldset>
        <fieldset>
        <legend>Product Requirements</legend>
          <asp:Literal ID="ltlProdReqs" runat="server" Text='<%#Eval("ProdReqDate") + " " + Eval("ProdReqNotes")%>' />
        </fieldset>
 
        <telerik:RadGrid ID="rgdWIPnotes" runat="server" DataSourceID="sqlWIPnotes" GridLines="None"
          AutoGenerateColumns="False" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
          AllowAutomaticUpdates="True" Skin="Hay" AutoGenerateColumns="True">
          <MasterTableView DataSourceID="sqlWIPnotes" DataKeyNames="NotesID" PageSize="10"
            CommandItemDisplay="Top" EditMode="InPlace"
            CommandItemSettings-AddNewRecordImageUrl="images/icons/add.png" CommandItemSettings-RefreshImageUrl="images/icons/database_refresh.png">
          </MasterTableView>
        </telerik:RadGrid>

      </NestedViewTemplate>
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Feb 2009, 08:21 AM
Hi Paul,

One suggestion for accomplishing this by placing an invisible Label to get the parameter and set the LabelID as the ControlParameter of the SqlDataSource which bind to the RadGrid inside NestedViewTemplate.

ASPX:
<NestedViewTemplate>    
          <fieldset> 
          <asp:Label ID="Label1" Text='<%# Eval("CustomerID") %>' Visible="false" runat="server" />    
                             
          <asp:SqlDataSource ID="DetailsDataSource" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Orders Where CustomerID = @CustomerID" runat="server">     
                     <SelectParameters>    
                                <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="CustomerID" />    
                     </SelectParameters>    
          </asp:SqlDataSource>    
    
          <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="True" DataSourceID="DetailsDataSource" GridLines="None">  
          </telerik:RadGrid>    
          </fieldset>    
</NestedViewTemplate>    
 

Hope this will help you.

Thanks,
Princy.
0
Paul Wood
Top achievements
Rank 1
answered on 15 Feb 2009, 10:44 PM
I had the hidden field and was trying to use the value in the code behind but I wasn't aware that you could use an SqlDataSource within a repeatable element like that. Wow, that makes things so much easier! Thanks.
0
Ken
Top achievements
Rank 1
answered on 26 May 2010, 09:04 PM

Hi,

The snippet you posted worked for me, however, when adding one more level for this, I have the same problem of always getting the first row. My Page is structure like this:

GridView1
    NestedGrid1 (This pulls the correct ID from Gridview1 based on the hidden Label  value)
        NestedGrid2 (Pulls ONLY the first row ID from NestedGrid2)

I used the same method in NestedGrid2 as I did for NestedGrid1.

Thanks in Advance,
Ken
Tags
Grid
Asked by
Paul Wood
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Paul Wood
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Ken
Top achievements
Rank 1
Share this question
or