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

Master table row collapses when trying to expand a details table row

9 Answers 502 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amy
Top achievements
Rank 1
Amy asked on 16 Jul 2013, 08:21 PM
Hi.  I'm experiencing an issue with the expand/collapse functionality of the radgrid.  I have a master table and two detail tables.  The desired functionality is for a user to be able to drill down to the 2nd detail table via the master table and first detail table.  I'm also hiding the expand/collapse icon in the first details table on rows where there would not be any data returned in the second details table, as it's pointless to have a user expand a row if there's not going to be any data. 

All of the databinding is done in the code-behind.  I'm using the needdatasource for the master table and the detailtablebind for the details tables.

Expanding rows in the master table works as expected; however, if I click on the expand/collapse icon in the first details table (to drill down to the second details table), then the row in the master table collapses.  I also have a pagerstyle added to the details table, and if I click on it to change the page number or size then the row in the master table collapses.  Thus my dilema is that anything I try to do in the first details table causes the row in the master table to collapse.

I am using the HideExpandColumnRecursive method, which is called in RadGrid PreRender, to hide the expand/collapse icon if a value for one of the columns in the first detail table is equal to 0 (i.e., there would be no data to display in the second detail table).

I've stepped through the code, and if I expand a row in the master table then I do go through the RadGrid ItemCommand; however, I never hit that sub routine if I try to expand a row in the first details table.

The demo shown at the link below is what I'm trying to accomplish, except I don't want all the rows expanded by default; I want them all initially collapsed and the user chooses which ones to expand.

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultvb.aspx?#qsf-demo-source

Could someone provide some insight as to what I'm missing/not understanding?  :)

Thanks!

9 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Jul 2013, 03:52 PM
Hello Amy,

I have attached a simple runnable demo based on the online example you posted below. Please test it on your end and then let me know whether it is working properly.

Regards,
Daniel
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.
0
Amy
Top achievements
Rank 1
answered on 19 Jul 2013, 07:12 PM
Hi,

I created a project in Visual Studio 2012 based on the sample files provided, but am getting errors saying "The name 'RadGrid1' does not exist in the current context".  Also, in the aspx page, Visual Studio is indicating it cannot find the event handlers for 'RadGrid1_DetailTableDataBind' and 'RadGrid1_NeedDataSource'.

Here's the web.config file...
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  -->
<configuration>
    <appSettings>
        <add key="Telerik.Skin" value="Default"/>
    </appSettings>
    <connectionStrings>
        <add name="SIFConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SIF.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
        <add name="NorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient" />
        <add name="SelfReferencingDbConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TELERIKSELFREFERENCINGDB;Integrated Security=True" providerName="System.Data.SqlClient" />
        <add name="NorthwindEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
        <add name="NorthwindEntities1" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
        <add name="NWEntities" connectionString="metadata=res://*/App_Code.NWModel.csdl|res://*/App_Code.NWModel.ssdl|res://*/App_Code.NWModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
    </connectionStrings>
    <system.web.extensions>
        <scripting>
            <webServices>
                <jsonSerialization maxJsonLength="50000000"></jsonSerialization>
            </webServices>
        </scripting>
    </system.web.extensions>
    <system.web>
        <globalization culture="bg-BG" uiCulture="bg-BG" />
        <sessionState cookieless="false" />
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
                <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
                <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
                <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
                <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            </assemblies>
            <buildProviders>
                <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
            </buildProviders>
        </compilation>
        <authentication mode="Forms">
            <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
        </authentication>
        <membership>
            <providers>
                <clear />
                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
            </providers>
        </membership>
        <profile>
            <providers>
                <clear />
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear />
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
            </providers>
        </roleManager>
        <httpHandlers>
            <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
            <add path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" validate="false" />
            <add path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" validate="false" />
        </httpHandlers>
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"></modules>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
            <add name="Telerik_Web_UI_SpellCheckHandler_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" />
            <add name="Telerik_Web_UI_DialogHandler_aspx" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" />
        </handlers>
    </system.webServer>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
</configuration>

I'm assuming I'm still missing a reference somewhere?

Thank you for your help!
0
Daniel
Telerik team
answered on 24 Jul 2013, 04:28 PM
Hello Amy,

This is a simple website. Please try the following steps in order to run the website:
- extract the folder from the archive
- put your binary files (Telerik.Web.UI.dll, Telerik.Web.UI.Skins.dll, and Telerik.Web.Design.dll) to the existing BIN folder
- open Visual Studio and select File -> Open -> Web Site...
- navigate to the extracted folder and then press Open

You may need to change the Target Framework (Property Pages from the context menu) if your DLL files doesn't match the web.config (4.0) or you can replace the whole web.config file with yours.
You can also tweak the database connection string in the web.config file if your current SQL instance name is different from the existing one.

Let me know whether this helps.

Regards,
Daniel
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.
0
Amy
Top achievements
Rank 1
answered on 26 Jul 2013, 02:50 PM
Daniel, thank you for your assistance; I was able to get the demo working without any errors. 

I've modified my code to mimic the demo, and now receive an error indicating that one of the columns in my 2nd details table "is neither a DataColumn nor a DataRelation for table Data."; the "Data" table is created when retrieving values from the database for the 2nd details table.  The field in question is called "contract_id", which is a value returned in both the 1st and 2nd details table; the 2nd details table needs the "contract_id" value from the 1st details table in order to populate with data.

If I step through the code, the DetailTableBind is called, I do get a value for "contract_id" and the function (i.e. get_items_grid) to get the data for the 2nd details table runs without error.  Once the DetailTableBind routine finishes, then I get the error message.

Here's what I have for the DetailTableBind...
Protected Sub RadGrid1_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind
    Dim parentItem As GridDataItem = e.DetailTableView.ParentItem
 
    'Make sure master table has Selections
    If parentItem Is Nothing Then
        e.DetailTableView.DataSource = Nothing
        e.DetailTableView.DataSource = Nothing
    Else
        Select Case e.DetailTableView.Name
            Case "dtvContracts"
                Dim sel_id As Integer = CInt(parentItem("sel_id").Text)
                e.DetailTableView.DataSource = get_contracts_grid(sel_id) 'returns a DataTable
 
            Case "dtvItems"
                Dim sel_id As Integer = CInt(parentItem("sel_id_dtv1").Text)
                Dim contract_id As Integer = CInt(parentItem("contract_id").Text)
                e.DetailTableView.DataSource = get_items_grid(sel_id, contract_id) 'returns a DataTable
 
        End Select
    End If
 
End Sub

Thank you again for your assistance!
0
Daniel
Telerik team
answered on 31 Jul 2013, 02:45 PM
Hello Amy,

Can you please check whether the contract_id variable is populated properly when following line is executed? You can do this in the debugger's window.
Dim contract_id As Integer = CInt(parentItem("contract_id").Text)

If this is so, please post your markup/control declaration here so that I can see if there is something wrong in your setup.

Regards,
Daniel
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.
0
Amy
Top achievements
Rank 1
answered on 31 Jul 2013, 05:25 PM
Daniel, I do get a value for the contractID, and have attached a screenshot for reference.  Below is the markup for the radgrid on the page...
<telerik:RadGrid ID="RadGrid1" runat="server" skin="Windows7" OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource"
        AllowSorting="True" AllowPaging="true" GridLines="None" Width="100%" >
 
        <MasterTableView DataKeyNames="sel_id" Width="100%" Name="mtvContracts" ShowHeader="true" CommandItemDisplay="Top"  AllowFilteringByColumn="True"
            NoMasterRecordsText="There are currently no active ELA Item Reviewing contracts at this time." HierarchyLoadMode="ServerBind">
             <CommandItemTemplate>
                <telerik:RadToolBar ID="RadToolBar1" runat="server" AutoPostBack="true" Skin="Windows7">
                    <Items>
                        <telerik:RadToolBarButton Text="Clear All Filters" CommandName="clear" ImageUrl="/TestDevelopment/audio/graphics/TDS/images/cancel.png"
                            ToolTip="Click to clear all filters in the grid below" />
                    </Items>
                </telerik:RadToolBar>
            </CommandItemTemplate>
            <%-- Contracts detail table--%>
            <DetailTables>
                <telerik:GridTableView runat="server" Name="dtvContracts" DataKeyNames="sel_id_dtv1" Width="100%" HierarchyLoadMode="ServerBind">
                    <%--<ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="sel_id_dtv1" MasterKeyField="sel_id" />
                    </ParentTableRelation>--%>
                    <%-- Items detail table--%>
                    <DetailTables>
                        <telerik:GridTableView Name="dtvItems" DataKeyNames="contract_id, sel_id," Width="100%" HierarchyLoadMode="ServerBind">
                            <%--<ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="sel_id" MasterKeyField="sel_id_dtv1" />
                                <telerik:GridRelationFields DetailKeyField="contract_id" MasterKeyField="contract_id" />
                            </ParentTableRelation>  --%>                         
                            <Columns>
                                <telerik:GridBoundColumn DataField="sel_id" UniqueName="sel_id" Display="true"/>
                                <telerik:GridBoundColumn DataField="contract_id" UniqueName="contract_id" Display="true"/>
                                <telerik:GridBoundColumn DataField="item_id"  HeaderText="ItemID"
                                    SortExpression="item_id" UniqueName="item_id" ReadOnly="true" ShowFilterIcon="false"
                                    HeaderStyle-Width="50px" Display="true"/>
                                <telerik:GridBoundColumn DataField="date_reviewed" HeaderText="Review Date"
                                    SortExpression="date_reviewed" UniqueName="date_reviewed" ReadOnly="true" HeaderStyle-Width="100px"
                                    Visible="true"/>
                                <telerik:GridBoundColumn DataField="obj_num" HeaderText="Objective" SortExpression="obj_num"
                                    UniqueName="obj_num" HeaderStyle-Width="50px" ReadOnly="true"/>
                                <telerik:GridBoundColumn DataField="stem" HeaderText="Stem" SortExpression="stem"
                                    UniqueName="stem" HeaderStyle-Width="250px" ReadOnly="true"/>                      
                            </Columns>
                        </telerik:GridTableView>
                    </DetailTables>                   
                    <Columns>
                        <telerik:GridBoundColumn DataField="sel_id_dtv1" DataType="System.Int32" UniqueName="sel_id_dtv1" Display="false"/>
                        <telerik:GridBoundColumn DataField="contract_id" DataType="System.Int32" HeaderText="Contract ID"
                            SortExpression="contract_id" UniqueName="contract_id" ReadOnly="true" ShowFilterIcon="false"
                            HeaderStyle-Width="50px" Display="true"/>
                        <telerik:GridBoundColumn DataField="is_active"  HeaderText="Active"
                            SortExpression="is_active" UniqueName="is_active" ReadOnly="true" ShowFilterIcon="false"
                            HeaderStyle-Width="25px" Display="true" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center"/>
                        <telerik:GridBoundColumn DataField="reviewer_name" DataType="System.String" HeaderText="Reviewer"
                            SortExpression="reviewer_name" UniqueName="reviewer_name" ReadOnly="true" HeaderStyle-Width="200px"
                            Visible="true"/>
                        <telerik:GridBoundColumn DataField="date_created" HeaderText="Date Created" SortExpression="date_created"
                            UniqueName="date_created" HeaderStyle-Width="100px" ReadOnly="true"/>
                        <telerik:GridBoundColumn DataField="date_start" HeaderText="Date Start" SortExpression="date_start"
                            UniqueName="date_start" HeaderStyle-Width="50px" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center"/>
                        <telerik:GridBoundColumn DataField="date_end" HeaderText="Date End" SortExpression="date_end"
                            UniqueName="date_end" HeaderStyle-Width="50px" ReadOnly="true" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center"/>
                        <telerik:GridBoundColumn DataField="num_items_assigned" HeaderText="# Assigned" SortExpression="num_items_assigned"
                            UniqueName="num_items_assigned" ReadOnly="true" HeaderStyle-Width="50px" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center" Visible="true"/>
                        <telerik:GridBoundColumn DataField="num_items_reviewed" HeaderText="# Reviewed" SortExpression="num_items_reviewed"
                            UniqueName="num_items_reviewed" ReadOnly="true" HeaderStyle-Width="50px" HeaderStyle-HorizontalAlign="Center"
                            ItemStyle-HorizontalAlign="Center" Visible="true"/>        
                    </Columns>
                </telerik:GridTableView>
                 
            </DetailTables>
            <Columns>
                <%--ObjType--%>
                <telerik:GridBoundColumn DataField="otype" HeaderText="CType" SortExpression="otype"
                    UniqueName="otype" AutoPostBackOnFilter="True" ShowFilterIcon="False" ShowSortIcon="true"
                    HeaderStyle-Width="100px" FilterControlWidth="85px" ReadOnly="true"/>
                <%--Grade--%>
                <telerik:GridBoundColumn DataField="grade" HeaderText="Grade" SortExpression="grade"
                    UniqueName="grade" AutoPostBackOnFilter="True" ShowFilterIcon="False" ShowSortIcon="true"
                    HeaderStyle-Width="100px" FilterControlWidth="85px" ReadOnly="true"/>
                <%--Subject--%>
                <telerik:GridBoundColumn DataField="subject_short" HeaderText="Subject" SortExpression="subject_short"
                    UniqueName="subject_short" AutoPostBackOnFilter="True" ShowFilterIcon="False"
                    ShowSortIcon="true" HeaderStyle-Width="100px" FilterControlWidth="85px" ReadOnly="true"/>
                <%--X2--%>
                <telerik:GridBoundColumn DataField="x2" HeaderText="X2" SortExpression="x2"
                    UniqueName="x2" AutoPostBackOnFilter="True" ShowFilterIcon="False" ShowSortIcon="true"
                    HeaderStyle-Width="50px" FilterControlWidth="35px" ReadOnly="true"/>
                <%--SelID--%>
                <telerik:GridBoundColumn DataField="sel_id" DataType="System.Int32" HeaderText="Sel ID"
                    SortExpression="sel_id" UniqueName="sel_id" ShowFilterIcon="false"
                    ShowSortIcon="true" HeaderStyle-Width="75px" FilterControlWidth="60px" AutoPostBackOnFilter="true"/>
                <%--Old SelID--%>
                <telerik:GridBoundColumn DataField="old_sel_id" DataType="System.Int32" HeaderText="Old Sel ID"
                    SortExpression="old_sel_id" UniqueName="old_sel_id" ShowFilterIcon="false"
                    ShowSortIcon="true" HeaderStyle-Width="75px" FilterControlWidth="60px" AutoPostBackOnFilter="true"/>
                <%--Title--%>
                <telerik:GridBoundColumn DataField="sel_title" HeaderText="Title" SortExpression="sel_title" HeaderStyle-Width="250px"
                    UniqueName="sel_title" ShowFilterIcon="False" ShowSortIcon="true" AutoPostBackOnFilter="True"/>
                <%--Author--%>
                <telerik:GridBoundColumn DataField="sel_author" HeaderText="Author" SortExpression="sel_author"
                    UniqueName="sel_author" HeaderStyle-Width="250px" ShowFilterIcon="False" ShowSortIcon="true" AutoPostBackOnFilter="True"/>
                <%--NumItems--%>
                <telerik:GridBoundColumn  DataField="num_items" HeaderText="Num Items" DataType="System.Int32" ShowFilterIcon="False"
                    ShowSortIcon="true" HeaderStyle-Width="50px" SortExpression="num_items" UniqueName="num_items"
                    AllowFiltering="false"/>
                <%--Invisible--%>
                <telerik:GridBoundColumn DataField="cgs_Id" DataType="System.Int32" UniqueName="cgs_Id" Display="false">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ItemStyle Font-Size="Small" VerticalAlign="Middle" />
        <AlternatingItemStyle Font-Size="Small" VerticalAlign="Middle"/>
        <PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="true" Position="TopAndBottom" />
        <GroupingSettings CaseSensitive="False" ShowUnGroupButton="true" />
        <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
            <Resizing AllowColumnResize="true" AllowResizeToFit="true" ResizeGridOnColumnResize="false"
                EnableRealTimeResize="true" />
        </ClientSettings>
        <SortingSettings SortedBackColor="OliveDrab" SortedAscToolTip="Click To Reverse Sort"
            SortedDescToolTip="Click To Remove Sort" EnableSkinSortStyles="false" />
    </telerik:RadGrid>


Thanks!
0
Amy
Top achievements
Rank 1
answered on 01 Aug 2013, 03:18 PM
I don't know if this is helpful, but if I uncomment the commented lines of code in the markup pertaining to the ParentTableRelation tags for the details tables, I get an error message that states there is a "syntax error in the expression" (although I don't see any syntax errors).

The stored procedure that populates the 1st details tables returns the following fields: contract_id, sel_id_dtv1, is_active, reviewer_name, date_created, date_start, date_end, num_items_assigned, and num_items_reviewed.  The stored procedure also returns a field called 'row_id', but that's used only in the stored procedure to manipulate the data that will be returned.

The stored procedure that populates the 2nd details table returns the following fields: contract_id, item_id, date_reviewed, obj_num, stem, and sel_id.

Thanks!
0
Daniel
Telerik team
answered on 05 Aug 2013, 05:26 PM
Hello Amy,

You shouldn't use declarative table relations when binding using DetailTableDataBind.
Nevertheless, I suppose the problem is caused by the data coming from your datasource as I'm able to run a simple demo based on your code locally. Would you be able to create a stripped, runnable version of your project (showing the problem) as I'd like to debug it locally?

Regards,
Daniel
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.
0
Amy
Top achievements
Rank 1
answered on 08 Aug 2013, 01:36 PM
Hi,

Yes, I realize the declarative table relations shouldn't be used in this scenario, but I figured I'd just see what happens if I did.  ;)

I'll try to create a stripped down version as soon as I can, and will also look back over my datasources.

Thank you!
Tags
Grid
Asked by
Amy
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Amy
Top achievements
Rank 1
Share this question
or