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

Self Referencing Hierarchy with an additional Detail table - Help Needed Please

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Casey
Top achievements
Rank 1
Casey asked on 05 Aug 2011, 08:16 PM
I put together a grid of categories that are self referencing which worked like expected. How I need to add in a detail table of products that could be associated with any level of the existing hierarchy. Please see the following for an example hierarchy:

Category 1
    Category 1a
    Category 1b
        Category 1b1
        Products for category 1b1
Category 2
    Category 2a
    Products for category 2a
Category 3

I am having issues adding the detail information. When I select to expand hierarchy from the main list of categories, nothing happens. None of the child categories appear and none of the products appear.
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Web20" 
    OnItemCreated="RadGrid1_ItemCreated"  
    OnItemDataBound="RadGrid1_ItemDataBound" OnColumnCreated="RadGrid1_ColumnCreated"
    AutoGenerateColumns="False" ShowStatusBar="True"
    CellSpacing="0" GridLines="None" AllowAutomaticInserts="True">
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
    <MasterTableView DataKeyNames="CATEGORY_CDE, PARENT_CDE" ShowHeader="true" 
        HierarchyDefaultExpanded="false" AllowSorting="true" 
        CommandItemDisplay="Bottom" editmode="InPlace" InsertItemDisplay="Bottom">
        <SelfHierarchySettings KeyName="CATEGORY_CDE" ParentKeyName="PARENT_CDE" />
        <DetailTables>
            <telerik:GridTableView runat="server" DataKeyNames="Category_Cde,Product_Cde" 
                DataMember="ProductList">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="Category_Cde" 
                        MasterKeyField="Category_Cde" />
                </ParentTableRelation>
                <CommandItemSettings ExportToPdfText="Export to PDF" />
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
            </telerik:GridTableView>
        </DetailTables>
    <CommandItemSettings ExportToPdfText="Export to PDF" 
            AddNewRecordText="Add New Category"></CommandItemSettings>
    <Columns>
        <telerik:GridExpandColumn FilterControlAltText="Filter ExpandColumn column" 
            Visible="True">
        </telerik:GridExpandColumn>
        <telerik:GridBoundColumn DataField="Category_Cde" UniqueName="Category_Cde" Visible="true">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Parent_cde" UniqueName="Parent_cde" Visible="true">
        </telerik:GridBoundColumn>
    </Columns>
    <EditFormSettings>
    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
    </EditFormSettings>
    </MasterTableView>
    <ClientSettings AllowExpandCollapse="true" />
    <FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>

Protected Sub RadGrid1_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    bindRadDataGrid()
End Sub
Sub bindRadDataGrid()
    Dim db As New WebCatVB.category
    categoryListInfo = db.GetCategoryList()
    RadGrid1.DataSource = categoryListInfo
End Sub
Protected Sub RadGrid1_DetailTableDataBind(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind
    Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
    If parentItem.Edit Then
        Return
    End If
    If (e.DetailTableView.DataMember = "ProductList") Then
        Dim db As New WebCatVB.product
        Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
        Dim cat As String = dataItem.GetDataKeyValue("CATEGORY_CDE").ToString()
        e.DetailTableView.DataSource = db.GetProductList(cat)
    End If
End Sub

Could someone take a quick look at the above code and let me know where my logic when wrong. I looked at similar forums but was unable to find what I was overlooking. Any assistance would be greatly appreciated.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 11 Aug 2011, 11:35 AM
Hi Casey,

I would advise you to use the RadTreeList control in this scenario. It handles self-referencing data with less limitations than RadGrid. Additionally, it offers a DetailTemplate to use for showing additional data about the items:
Detail Template

This feature should help you get the desired detail look.

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

Tags
Grid
Asked by
Casey
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or