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

RadGrid using multiple datakeynames - doesnt work

1 Answer 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Avo
Top achievements
Rank 1
Avo asked on 23 Oct 2012, 02:51 PM
Hi,

I am trying to use the following code to create a hierarchical grid.  It works all the way until the grid is expanded to the UserLocationVendorModel GridView (bolded code below).  This gridview (table) needs two keys (LocationID and VendorName) passed from the selection on the third level.  Could you tell me if I am missing something?  I have attached a screenshot of how the grid is not working on the last level.
 
VB.NET Code:

DefineGridStructure is called in the Page_Load event of the ASP.Net page.

 Private Sub DefineGridStructure()

        Dim RadGrid4 As RadGrid = New RadGrid

        RadGrid4.DataSourceID = "SqlDataSource1"
        RadGrid4.MasterTableView.DataKeyNames = New String() {"LocationID"}
        RadGrid4.Width = Unit.Percentage(100)
        RadGrid4.PageSize = 15
        RadGrid4.AllowPaging = True
        RadGrid4.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
        RadGrid4.AutoGenerateColumns = False
        RadGrid4.Skin = "Outlook"


        'Add Location table
        RadGrid4.MasterTableView.Width = Unit.Percentage(100)


        Dim boundColumn As GridBoundColumn
        boundColumn = New GridBoundColumn()
        RadGrid4.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = "LocationID"
        boundColumn.HeaderText = "LocationID"
        boundColumn = New GridBoundColumn()
        RadGrid4.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = "Description"
        boundColumn.HeaderText = "Description"
        boundColumn = New GridBoundColumn()
        RadGrid4.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = "ParentId"
        boundColumn.HeaderText = "ParentId"
        boundColumn = New GridBoundColumn()
        RadGrid4.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = "EditStatus"
        boundColumn.HeaderText = "EditStatus"
        boundColumn = New GridBoundColumn()
        RadGrid4.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = "ModificationSeq"
        boundColumn.HeaderText = "ModificationSeq"
        RadGrid4.AllowFilteringByColumn = True


        'Add UserLocation table
        Dim tableUserLocation As New GridTableView(RadGrid4)
        tableUserLocation.DataSourceID = "SqlDataSource2"
        tableUserLocation.DataKeyNames = New String() {"LocationID"}
        tableUserLocation.Width = Unit.Percentage(100)
        Dim relationFields As GridRelationFields = New GridRelationFields()
        relationFields.MasterKeyField = "LocationID"
        relationFields.DetailKeyField = "LocationID"
        tableUserLocation.ParentTableRelation.Add(relationFields)


        RadGrid4.MasterTableView.DetailTables.Add(tableUserLocation)


        'Add Columns
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "LocationID"
        boundColumn.HeaderText = "LocationID"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "Member"
        boundColumn.HeaderText = "Member"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "HasChild"
        boundColumn.HeaderText = "HasChild"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "Kount"
        boundColumn.HeaderText = "Kount"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "Pct"
        boundColumn.HeaderText = "Pct"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "TotalCounter"
        boundColumn.HeaderText = "TotalCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "PrinterCounter"
        boundColumn.HeaderText = "PrinterCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "CopyCounter"
        boundColumn.HeaderText = "CopyCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "FaxCounter"
        boundColumn.HeaderText = "FaxCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocation.Columns.Add(boundColumn)
        boundColumn.DataField = "ScanCounter"
        boundColumn.HeaderText = "ScanCounter"


        'Add UserLocationVendor table
        Dim tableUserLocationVendor As New GridTableView(RadGrid4)
        tableUserLocationVendor.DataSourceID = "SqlDataSource3"
        tableUserLocationVendor.DataKeyNames = New String() {"LocationID"}
        tableUserLocationVendor.Width = Unit.Percentage(100)
        Dim relationFields2 As GridRelationFields = New GridRelationFields()


        relationFields2.MasterKeyField = "LocationID"
        relationFields2.DetailKeyField = "LocationID"
        tableUserLocationVendor.ParentTableRelation.Add(relationFields2)
        tableUserLocation.DetailTables.Add(tableUserLocationVendor)


        'Add columns
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "LocationID"
        boundColumn.HeaderText = "LocationID"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "VendorName"
        boundColumn.HeaderText = "VendorName"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "Kount"
        boundColumn.HeaderText = "Kount"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "Pct"
        boundColumn.HeaderText = "Pct"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "TotalCounter"
        boundColumn.HeaderText = "TotalCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "PrinterCounter"
        boundColumn.HeaderText = "PrinterCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "CopyCounter"
        boundColumn.HeaderText = "CopyCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "FaxCounter"
        boundColumn.HeaderText = "FaxCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendor.Columns.Add(boundColumn)
        boundColumn.DataField = "ScanCounter"
        boundColumn.HeaderText = "ScanCounter"


        'Add UserLocationVendorModel table
        Dim tableUserLocationVendorModel As New GridTableView(RadGrid4)
        tableUserLocationVendorModel.DataSourceID = "SqlDataSource4"
        tableUserLocationVendorModel.DataKeyNames = New String() {"LocationID", "VendorName"}
        tableUserLocationVendorModel.Width = Unit.Percentage(100)
        Dim relationFields3 As GridRelationFields = New GridRelationFields
        relationFields3.MasterKeyField = "LocationID,VendorName"
        relationFields3.DetailKeyField = "LocationID,VendorName"
        tableUserLocationVendorModel.ParentTableRelation.Add(relationFields3)
        tableUserLocationVendor.DetailTables.Add(tableUserLocationVendorModel)



        'Add columns
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "LocationID"
        boundColumn.HeaderText = "LocationID"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "VendorName"
        boundColumn.HeaderText = "VendorName"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "ModelName"
        boundColumn.HeaderText = "ModelName"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "Kount"
        boundColumn.HeaderText = "Kount"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "Pct"
        boundColumn.HeaderText = "Pct"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "TotalCounter"
        boundColumn.HeaderText = "TotalCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "PrinterCounter"
        boundColumn.HeaderText = "PrinterCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "CopyCounter"
        boundColumn.HeaderText = "CopyCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "FaxCounter"
        boundColumn.HeaderText = "FaxCounter"
        boundColumn = New GridBoundColumn()
        tableUserLocationVendorModel.Columns.Add(boundColumn)
        boundColumn.DataField = "ScanCounter"
        boundColumn.HeaderText = "ScanCounter"


        Me.PlaceHolder1.Controls.Add(RadGrid4)


End Sub

Aspx Code:


        <telerik:RadGrid ID="RadGrid4" runat="server" gridLines="Both">
             </telerik:RadGrid>
                         
             
                    <div style="width:730px;">
                    <asp:SqlDataSource ID="SqlDataSource1" 
                          ConnectionString="<%$ ConnectionStrings:DSN %>"
                          ProviderName="<%$ ConnectionStrings:DSN.ProviderName %>"
                          SelectCommand="GetLocationsByParentLocationId" runat="server" 
                                    SelectCommandType="StoredProcedure">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="CompanyID" SessionField="CompanyID" />
                                        <asp:SessionParameter Name="LocationID" SessionField="InitialLocationID" />
                                   </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:SqlDataSource ID="SqlDataSource2" 
                          ConnectionString="<%$ ConnectionStrings:DSN %>"
                          ProviderName="<%$ ConnectionStrings:DSN.ProviderName %>"
                          SelectCommand="Report_PopulationByUserLocation_New_Test" runat="server"
                                    SelectCommandType="StoredProcedure">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="aiUserUniqueID" SessionField="UserID" />                                       
                                        <asp:Parameter Name="LocationID" Type="int32" />
                                        <asp:SessionParameter Name="asCompanyID" SessionField="CompanyID" />
                                    </SelectParameters>
                    </asp:SqlDataSource>
                                        <asp:SqlDataSource ID="SqlDataSource3" 
                          ConnectionString="<%$ ConnectionStrings:DSN %>"
                          ProviderName="<%$ ConnectionStrings:DSN.ProviderName %>"
                          SelectCommand="Report_PopulationByUserLocationVendor_New_Test" runat="server"
                                    SelectCommandType="StoredProcedure">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="aiUserUniqueID" SessionField="UserID" />
                                        <asp:Parameter Name="LocationID" Type="int32" />
                                    </SelectParameters>
                    </asp:SqlDataSource>
                                        <asp:SqlDataSource ID="SqlDataSource4" 
                          ConnectionString="<%$ ConnectionStrings:DSN %>"
                          ProviderName="<%$ ConnectionStrings:DSN.ProviderName %>"
                          SelectCommand="Report_PopulationByUserLocationVendorModel_New_Test" runat="server"
                                    SelectCommandType="StoredProcedure">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="aiUserUniqueID" SessionField="UserID" />
                                        <asp:Parameter Name="LocationID" Type="int32" />
                                        <asp:Parameter Name="VendorName" Type="string" />
                                        <asp:SessionParameter Name="asURL" SessionField="URL" />
                                    </SelectParameters>
                    </asp:SqlDataSource>
                    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                    </telerik:RadAjaxManager>

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Oct 2012, 04:49 AM
Hello Avo,

When you have a parent table relation with multiple fields you should create a separate GridRelationFields object for each pair and add it to the parent table relation object:

Dim relationFields3 As GridRelationFields = New GridRelationFields
relationFields3.MasterKeyField = "LocationID"
relationFields3.DetailKeyField = "LocationID"
tableUserLocationVendorModel.ParentTableRelation.Add(relationFields3)
 
Dim relationFields4 As GridRelationFields = New GridRelationFields
relationFields4.MasterKeyField = "VendorName"
relationFields4.DetailKeyField = "VendorName"
tableUserLocationVendorModel.ParentTableRelation.Add(relationFields4)
 
tableUserLocationVendor.DetailTables.Add(tableUserLocationVendorModel)


Hope it helps.


Greetings, Tsvetoslav
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
Avo
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or