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

radgrid - self-referencing and hierarchical at the same time

1 Answer 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jean-marc
Top achievements
Rank 1
jean-marc asked on 23 Dec 2013, 05:44 PM
Hello,

I want to use a hierarchical radgrid using self-referencing on the masterview and a detail view at the same time. Is it possible ?
Here the source code of my page 
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/OEECalcul/general2.Master" CodeBehind="TFGroupsProductsDetails.aspx.vb" Inherits=".TFGroupsProductsDetails" %>
<%@ Register Src="ctrl/img_status.ascx" TagName="imgStatus" TagPrefix="uc1" %>
<%@ Reference Control="~/OEECalcul/ctrl/img_status.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="OEEDirectContent" runat="server">
    <telerik:RadGrid ID="rGrid" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" CellSpacing="0" Culture="fr-FR" GridLines="None" ShowGroupPanel="True" AutoGenerateColumns="False">
        <MasterTableView AllowSorting="true" DataKeyNames="id_groups_products, id_parent" Width="100%">
            <Columns>
                <telerik:GridTemplateColumn HeaderText="Status">
                    <ItemTemplate>
                        <uc1:imgStatus ID="img_status1" runat="server" Status='<%# Eval("id_status")%>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderText="Nom" datafield="name" />
                <telerik:GridMaskedColumn DataField="id_groups_products" UniqueName="id_groups_products" DataType="System.Guid" />
            </Columns>
            <SelfHierarchySettings ParentKeyName="id_parent" KeyName="id_groups_products" />
            <DetailTables>
                <telerik:GridTableView Caption="Produits associĆ©s" runat="server" DataKeyNames="id_product">
                    <Columns>
                        <telerik:GridTemplateColumn HeaderText="Status">
                            <ItemTemplate>
                                <uc1:imgStatus ID="img_status1" runat="server" Status='<%# Eval("id_status")%>' />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn HeaderText="Nom" datafield="name" />
                        <telerik:GridMaskedColumn DataType="System.Guid" DataField="id_product" UniqueName="id_product" />
                    </Columns>
                    <ParentTableRelation>
                        <telerik:GridRelationFields MasterKeyField="id_groups_products" DetailKeyField="id_groups_products" />
                    </ParentTableRelation>
                </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="True">
        </ClientSettings>
    </telerik:RadGrid>
</asp:Content>

and the code behind :
I
Imports System.Data.SqlClient
Imports Telerik.Web.UI
 
Public Class TFGroupsProductsDetails
    Inherits System.Web.UI.Page
 
    Private Function GetDataTable() As DataTable
        Dim c As New SqlConnection(GetConnectionString(Session("DbName")))
        c.Open()
        Dim cmd As SqlCommand = c.CreateCommand
        cmd.CommandText = "create table #tempGP " & _
            "(id_groups_products uniqueidentifier, " & _
            "name nvarchar(50), " & _
            "descript nvarchar(max), " & _
            "id_parent uniqueidentifier, " & _
            "num_order int, " & _
            "id_status int)"
 
        cmd.ExecuteNonQuery()
        cmd = c.CreateCommand
        cmd.CommandText = "insert #tempGP select id_groups_products, name, descript, id_parent, num_order, id_status from groups_products"
        cmd.ExecuteNonQuery()
 
        Dim adapter As New SqlDataAdapter
        adapter.SelectCommand = New SqlCommand("select id_groups_products, name, descript, id_parent, num_order, id_status from groups_products", c)
        Dim myDataTable As New DataTable
        Try
            adapter.Fill(myDataTable)
        Finally
            c.Close()
        End Try
 
        Return myDataTable
    End Function
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If rGrid.EnableLinqExpressions Then
            rGrid.MasterTableView.FilterExpression = "it[""id_parent""] = Convert.DBNull"
        Else
            rGrid.MasterTableView.FilterExpression = "id_parent IS NULL"
        End If
 
    End Sub
 
    Private Sub rGrid_DetailTableDataBind(sender As Object, e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles rGrid.DetailTableDataBind
        Dim parentItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
        If parentItem.Edit Then
            Return
        End If
 
        Dim c As New SqlConnection(GetConnectionString(Session("DbName")))
        c.Open()
        Dim adapter As New SqlDataAdapter
        adapter.SelectCommand = New SqlCommand("select id_product, name, descript, id_groups_products, num_order, id_status from products where id_groups_products='" + Guid.Parse(parentItem("id_groups_products").Text).ToString + "'", c)
        Dim myDataTable As New DataTable
        Try
            adapter.Fill(myDataTable)
        Finally
            c.Close()
        End Try
 
        e.DetailTableView.DataSource = myDataTable
    End Sub
 
    Private Sub rGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rGrid.NeedDataSource
        rGrid.DataSource = GetDataTable()
    End Sub
 
End Class

i succes to get first level, but i get an issue each time a want to expand a item containing details. 

[EvaluateException: Impossible de trouver la colonne [id_parent].]
   System.Data.NameNode.Bind(DataTable table, List`1 list) +1283261
   System.Data.BinaryNode.Bind(DataTable table, List`1 list) +34
   System.Data.UnaryNode.Bind(DataTable table, List`1 list) +29
   System.Data.UnaryNode.Bind(DataTable table, List`1 list) +29
   System.Data.DataExpression.Bind(DataTable table) +84
   System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +5314983
   System.Data.DataView.set_RowFilter(String value) +141
   System.Data.LinqDataView.set_RowFilter(String value) +46
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +500
   Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +18
   Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray, Boolean shouldClearDataKeys) +131
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1142
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +816
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   Telerik.Web.UI.GridTableView.PerformSelect() +16
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   Telerik.Web.UI.GridTableView.DataBind() +274
   Telerik.Web.UI.GridDataItem.OnExpand() +348
   Telerik.Web.UI.GridItem.set_Expanded(Boolean value) +140
   Telerik.Web.UI.GridExpandCommandEventArgs.ExecuteCommand(Object source) +38
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +91
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +87
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +114
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +252
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Thanks for your help

regards

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Dec 2013, 03:59 PM
Hi Jean-Mark,

Please note that self-referencing RadGrid hierarchy is obsolete and we highly suggest that you use RadTreeList:
http://demos.telerik.com/aspnet-ajax/treelist/examples/overview/defaultcs.aspx

Or standard RadGrid hierarchy:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarative-relations/defaultcs.aspx

Please let us know if new questions arise.

Regards,
Eyup
Telerik
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 the blog feed now.
Tags
Grid
Asked by
jean-marc
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or