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

Designing the Master and Detail

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SDI
Top achievements
Rank 1
SDI asked on 13 Aug 2012, 10:49 PM
Hello Telerik,

I build the grid columns and set up the relationships in aspx and the data source is set in code-behind. The gird changes depending on a node selection which sends in a ID to filter out the master grid, which in turn filters out the detail grid based off the relationship.

Here is the grid in aspx:
<telerik:RadGrid runat="server" ID="RadGridMemberBoardPosition" Width="350px" Height="460px" AutoGenerateColumns="false"  >
    <MasterTableView DataKeyNames="MemberId" >
                                 
        <Columns>
            <telerik:GridClientSelectColumn ItemStyle-Width="10%"/>
            <telerik:GridBoundColumn DataField="Name" DataType="System.String" HeaderText="Name" UniqueName="Name" />
        </Columns>
 
        <DetailTables >
            <telerik:GridTableView DataKeyNames="MemberId">
                <Columns>
                    <telerik:GridBoundColumn DataField="FullName" DataType="System.String" HeaderText="FullName" UniqueName="FullName" />
                    <telerik:GridBoundColumn DataField="EmailAddress" DataType="System.String" HeaderText="EmailAddress" UniqueName="EmailAddress" />
                </Columns>
            </telerik:GridTableView>                                   
        </DetailTables>
 
        <ParentTableRelation>
            <telerik:GridRelationFields DetailKeyField="MemberId" MasterKeyField="MemberId" />
        </ParentTableRelation>
 
    </MasterTableView>
    <ClientSettings Selecting-AllowRowSelect="true" Scrolling-AllowScroll="true" />
</telerik:RadGrid>

Now in code behind i change the data with the node being selected in a TreeView on the page.

Protected Sub RadTreeViewGroups_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeViewGroups.NodeClick
 
    If Me.m_cMyManager Is Nothing Then
        Me.m_cMyManager = New cMyManager
    End If
 
    ' get the board positions and the members for those postions - hierarchical grid
    Me.RadGridMemberBoardPosition.DataSource = Me.GetGroupBoardPositionDT(Me.m_cMyManager, e.Node.Attributes("GroupId"))
    Me.RadGridMemberBoardPosition.Rebind()
 
End Sub

This code works fine for filling in the master table with the appropriate records. Now when a record is expanded by clicking its arrow - showing the detail grid it is always nothing.

This is the data source for the detail - setup in the page load.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    If Me.m_cMyManager Is Nothing Then
        Me.m_cMyManager = New cMyManager
    End If
  
    ' get the sql datasource for the detail of the datagrid
    Dim mySqlDataSource As New SqlDataSource("System.Data.SqlClient", Me.m_cMyManager.MyDb.ConnectionString(), Me.GetBoardPositionMembersQuery(Me.m_cMyManager))
    ' add the parameters
    Dim myParameter As New UI.WebControls.Parameter("MemberId", DbType.Int64)
    mySqlDataSource.SelectParameters.Add(myParameter)
 
    Me.RadGridMemberBoardPosition.MasterTableView.DetailTables(0).DataSource = mySqlDataSource
 
End Sub

I also tried to put it in the Handles RadGridMemberBoardPosition.DetailTableDataBind event, but it still failed to show the records related to the master table. This is a little different than your example http://demos.telerik.com/aspnet-ajax/grid/examples/programming/hierarchy/defaultvb.aspx  so I was wondering if it should all be in the code-behind. Also, if this will work in my scenario with a node changing the data source of a master and detail tables at run-time. 

Can you shed some light on this?

Thanks!
SDI




1 Answer, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 17 Aug 2012, 05:10 AM
Hi,

In order to achieve your goal please follow the approach shown in this online demo application. The approach you need to use is the same except for the part where you are taking the parameter from.


Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
SDI
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or