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

Use Detail Table for MasterTable Column

5 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt Dowling
Top achievements
Rank 1
Matt Dowling asked on 26 Aug 2008, 08:40 PM
I have a Grid, that is using a single datasource, but one of the columns is a text field and can be exceptionally long. I would like to use the a detail table to host this information so that it is hidden down below, so if they want to see the MessageBody of the row, they have to expand the details view, is this possible?

The data look something like this:

ID    Name    Date    Action     MessageBody

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Aug 2008, 04:20 AM
Hi Matt,

You can use Grid hiearachy to achieve the desired scenario. Bind both Master and Detail tables with the same DataSource. Add only one column in the detail table and set its DataField = "MessageBody". Also set the ParentTableRelation in the Detail table.

ASPX:
  <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
            GridLines="None"
            <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="ID"
                <Columns> 
                    <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID" > 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="Name" DataField="Name" HeaderText="Name" > 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn UniqueName="Date" DataField="Date" HeaderText="Date" > 
                    </telerik:GridBoundColumn> 
                     <telerik:GridBoundColumn UniqueName="Action" DataField="Action" HeaderText="Action" > 
                    </telerik:GridBoundColumn> 
                     
                </Columns> 
                 <DetailTables> 
                   <telerik:GridTableView DataSourceID="SqlDataSource1" runat="server" DataKeyNames="ID" > 
                    <ParentTableRelation> 
                            <telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" /> 
                        </ParentTableRelation> 
                    <Columns> 
                       <telerik:GridBoundColumn UniqueName="MessageBody" DataField="MessageBody" HeaderText="MessageBody" > 
                    </telerik:GridBoundColumn> 
                    </Columns> 
                   </telerik:GridTableView> 
                 </DetailTables> 
            </MasterTableView> 
        </telerik:RadGrid> 


Thanks
Princy.
0
Matt Dowling
Top achievements
Rank 1
answered on 27 Aug 2008, 04:40 PM
Here is what I have so far.


<
telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"   
            GridLines="None" DataSourceID="appMessageDataSource" Skin="Hay" > 
            <MasterTableView DataSourceID="appMessageDataSource" DataKeyNames="MessageId">  
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="MessageId" DataType="System.Int32" HeaderText="MessageId" SortExpression="MessageId" UniqueName="MessageId" /> 
                    <telerik:GridBoundColumn DataField="MessageDate" DataType="System.DateTime" HeaderText="Date" SortExpression="MessageDate" UniqueName="MessageDate" /> 
                    <telerik:GridBoundColumn DataField="MessageUserName" HeaderText="User Name" SortExpression="MessageUserName" UniqueName="MessageUserName" /> 
                    <telerik:GridBoundColumn DataField="AppActionName" HeaderText="Action" SortExpression="AppActionName" UniqueName="AppActionName" /> 
                </Columns> 
                <DetailTables> 
                    <telerik:GridTableView ShowHeader="false" DataSourceID="appMessageDataSource" DataKeyNames="MessageId">  
                        <ParentTableRelation> 
                            <telerik:GridRelationFields DetailKeyField="MessageId" MasterKeyField="MessageId" /> 
                        </ParentTableRelation> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="Body" UniqueName="Body" /> 
                        </Columns> 
                    </telerik:GridTableView> 
                </DetailTables> 
            </MasterTableView> 
        </telerik:RadGrid> 

This doesn't work because say i have 2 messages, MessageID 1 and MessageID 2. I get 2 parent rows, and the detail table of each parent row has both bodies.

The data from the datasource looks like this:
MessageID    Date            Body            Action     User                                   
1                    9/1/2008    Body for 1    Update    Matt
2                    9/2/2008    Body for 2    Update    Matt

The result looks like this

  • MessageID    Date            Action     User
  • 1                    9/1/2008     Update    Matt
    • Body
    • Body for 1
    • Body for 2
  • 2                   9/2/2008     Update    Matt
    • Body
    • Body for 1
    • Body for 2
 There should only be 1 body in each detail table, but it gets both. Any ideas?
0
Matt Dowling
Top achievements
Rank 1
answered on 27 Aug 2008, 07:06 PM
Additionally I am using an ObjectDataSource, not sure if that matters. but I just wanted to be through.
0
Princy
Top achievements
Rank 2
answered on 28 Aug 2008, 05:29 AM
Hi Matt,

Here is the code I tried on my end to set up a hierarchical relationship as you have mentioned. In this case I have used two SqlDataSources set to the same table from the DataBase.

Here is the Aspx I tried:

<telerik:RadGrid ID="RadGrid1" runat="server"   AllowMultiRowEdit="True"   AllowPaging="True" PageSize="3" AllowMultiRowSelection="True" DataSourceID="SqlDataSource1" GridLines="None" > 
             
            <MasterTableView DataSourceID="SqlDataSource1"   ShowFooter="True"  Name="Master"     AllowSorting="True" DataKeyNames="RollNo"    CommandItemDisplay="Top"  > 
               
                <Columns> 
                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" 
                        UniqueName="FirstName"
                      <FooterStyle  HorizontalAlign="Right" /> 
                          
                    </telerik:GridBoundColumn> 
                    
                    <telerik:GridBoundColumn DataField="RollNo" DataType="System.Int32" HeaderText="RollNo" 
                        SortExpression="RollNo" UniqueName="RollNo"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Division" DataType="System.Int32" HeaderText="Division" 
                        SortExpression="Division" UniqueName="Division"
                    </telerik:GridBoundColumn> 
                     
                </Columns> 
                
                <DetailTables> 
                 <telerik:GridTableView runat="server" Name="Detail"  DataKeyNames="RollNo" DataSourceID="SqlDataSource2" > 
                   <ParentTableRelation> 
                    <telerik:GridRelationFields  DetailKeyField="RollNo" MasterKeyField="RollNo" /> 
                   </ParentTableRelation> 
                   <Columns> 
                    <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName" 
                        UniqueName="LastName"
                    </telerik:GridBoundColumn> 
                   
                   </Columns> 
                 </telerik:GridTableView> 
                </DetailTables> 
                   
            </MasterTableView> 
             
        </telerik:RadGrid> 

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDataBaseConnectionString %>" 
            SelectCommand="SELECT * FROM [Students]"
        </asp:SqlDataSource> 
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MyDataBaseConnectionString %>" 
            SelectCommand="SELECT [LastName], [RollNo] FROM [Students] WHERE ([RollNo] = @RollNo)"
            <SelectParameters> 
                <asp:Parameter Name="RollNo" Type="Int32" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 


Thanks
Princy.
0
Matt Dowling
Top achievements
Rank 1
answered on 28 Aug 2008, 04:02 PM
This is the route I'm taking but you would think that making a second trip to the database is kind of wasteful considering the first query already has the desired data. I really don't want to make a 2 database calls for a single row. For now, this is what I'm going to do, but it less than optimal.

Matt
Tags
Grid
Asked by
Matt Dowling
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Matt Dowling
Top achievements
Rank 1
Share this question
or