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
and the code behind :
I
i succes to get first level, but i get an issue each time a want to expand a item containing details.
Thanks for your help
regards
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.SqlClientImports Telerik.Web.UIPublic 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 SubEnd Classi 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) +1724Thanks for your help
regards
