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

[Solved] Hierarchical grid loses child tables after postback

1 Answer 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 21 Aug 2013, 07:05 PM

Hi,

I have problem with hierarchical grid. It loses child tables and data after postback. The problem is with my own component which wraps grid with search textbox control.

If I'm using grid without my component it works correctly:

<telerik:RadGrid ID="grd" runat="server" PageSize="40" DataSourceID="ds1" AllowPaging="true" AllowAutomaticDeletes="true" Width="650px"
        OnSelectedIndexChanged="userList_ResultGrid_SelectedIndexChanged" OnItemDeleted="userList_ResultGrid_ItemDeleted">
        <MasterTableView AutoGenerateColumns="false" DataKeyNames="Id" ClientDataKeyNames="Id" HierarchyLoadMode="Client">
            <DetailTables>
                <telerik:GridTableView DataSourceID="ds2" DataKeyNames="Id" ClientDataKeyNames="Id" Width="100%" Name="UserRoles" AutoGenerateColumns="false" AllowPaging="false" NoDetailRecordsText="No additional roles assigned with this user.">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="PrimaryUserId" MasterKeyField="Id" />
                    </ParentTableRelation>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Role.Title" HeaderText="Role" />
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridTemplateColumn HeaderText="">
                    <HeaderStyle Width="32px" />
                    <ItemTemplate>
                        <asp:Panel ID="Active" runat="server" Style="height: 16px; width: 16px;" CssClass='<%# (bool)Eval("Active") ? "active-user" : "disabled-user" %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="User Name" />
                <telerik:GridBoundColumn DataField="Email" HeaderText="Login" />
                <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this user?"
                    ConfirmDialogType="Classic" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"
                    Text="Delete" UniqueName="DeleteColumn" ImageUrl="~/Data/Skins/First/Grid/Delete.png">
                    <HeaderStyle Width="32px" />
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowContextMenu="users_RowContextMenu" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" EnableVirtualScrollPaging="True" />
        </ClientSettings>
    </telerik:RadGrid>
    <asp:EntityDataSource ID="ds1" runat="server" ContextTypeName="ImpersonatedSecurityEntities" EntitySetName="Users" Where="it.PrimaryUserId is null" />
    <asp:EntityDataSource ID="ds2" runat="server" ContextTypeName="ImpersonatedSecurityEntities" EntitySetName="Users" Where="it.PrimaryUserId = @PrimaryUserId">
        <WhereParameters>
            <asp:Parameter Name="PrimaryUserId" DbType="Guid" />
        </WhereParameters>
    </asp:EntityDataSource>

I'm using my component more than 1 year without problems but I never defined hierarchy. Now I added hierarchy and it does not work. Here is the code:

<bfo:GridSmartSearch ID="userList" runat="server" ShowAlphabeticPager="true" AlphabeticPagerType="Full"
    GridSmartSearchType="AjaxManager">
    <SearchTextBox EmptyMessage="Type here to search users..." Width="250px" />
    <ResultGrid PageSize="40" AllowPaging="true" AllowAutomaticDeletes="true" Width="650px"
        OnSelectedIndexChanged="userList_ResultGrid_SelectedIndexChanged" OnItemDeleted="userList_ResultGrid_ItemDeleted">
        <MasterTableView AutoGenerateColumns="false" DataKeyNames="Id" ClientDataKeyNames="Id" HierarchyLoadMode="Client">
            <DetailTables>
                <telerik:GridTableView DataSourceID="dsA" DataKeyNames="Id" ClientDataKeyNames="Id" Width="100%" Name="UserRoles" AutoGenerateColumns="false" AllowPaging="false" NoDetailRecordsText="No additional roles assigned with this user.">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="PrimaryUserId" MasterKeyField="Id" />
                    </ParentTableRelation>
                    <Columns>
                        <telerik:GridBoundColumn DataField="Role.Title" HeaderText="Role" />
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridTemplateColumn HeaderText="">
                    <HeaderStyle Width="32px" />
                    <ItemTemplate>
                        <asp:Panel ID="Active" runat="server" Style="height: 16px; width: 16px;" CssClass='<%# (bool)Eval("Active") ? "active-user" : "disabled-user" %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="User Name" />
                <telerik:GridBoundColumn DataField="Email" HeaderText="Login" />
                <telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this user?"
                    ConfirmDialogType="Classic" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"
                    Text="Delete" UniqueName="DeleteColumn" ImageUrl="~/Data/Skins/First/Grid/Delete.png">
                    <HeaderStyle Width="32px" />
                    <ItemStyle HorizontalAlign="Center" />
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true" />
            <ClientEvents OnRowContextMenu="users_RowContextMenu" />
            <Scrolling AllowScroll="True" UseStaticHeaders="True" EnableVirtualScrollPaging="True" />
        </ClientSettings>
    </ResultGrid>
    <DataSource TypeName="Bfgl.First.Web.UI.UsersGridSmartSearchDataSource" DeleteMethod="Delete">
        <SelectParameters>
            <asp:ControlParameter Name="category" ControlID="cmdUserFilterCategory" ConvertEmptyStringToNull="true" />
            <asp:ControlParameter Name="roleId" ControlID="cmdUserFilterRole" ConvertEmptyStringToNull="true" />
        </SelectParameters>
    </DataSource>
    <ControlsContainer>
        <asp:EntityDataSource ID="ds2" runat="server" ContextTypeName="Bfgl.First.Security.Data.Models.ImpersonatedSecurityEntities" EntitySetName="Users" Where="it.PrimaryUserId = @PrimaryUserId">
            <WhereParameters>
                <asp:Parameter Name="PrimaryUserId" DbType="Guid" />
            </WhereParameters>
        </asp:EntityDataSource>
    </ControlsContainer>
</bfo:GridSmartSearch>

And here are key parts of GridSmartSearch component:

public partial class GridSmartSearch : RadWebControl, INamingContainer
    {
        private RadTextBox searchTextBox;
        [Browsable(false)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public RadTextBox SearchTextBox
        {
            get
            {
                if (this.searchTextBox == null)
                {
                    this.searchTextBox = new RadTextBox();
                }
                return this.searchTextBox;
            }
        }
 
        private RadGrid resultGrid;
        [Browsable(false)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public RadGrid ResultGrid
        {
            get
            {
                if (this.resultGrid == null)
                {
                    this.resultGrid = new RadGrid();
                }
                return this.resultGrid;
            }
        }
 
        private ObjectDataSource dataSource;
        [Browsable(false)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public ObjectDataSource DataSource
        {
            get
            {
                if (this.dataSource == null)
                {
                    this.dataSource = new ObjectDataSource();
                }
                return this.dataSource;
            }
        }
 
        private Panel controlsContainer;
        [Browsable(false)]
        [PersistenceMode(PersistenceMode.InnerProperty)]
        public Panel ControlsContainer
        {
            get
            {
                if (this.controlsContainer == null)
                {
                    this.controlsContainer = new Panel();
                }
                return this.controlsContainer;
            }
        }
 
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
 
            this.Controls.Clear();
 
            this.ConfigureView();
            this.ConfigureDataSource();
 
            if (String.IsNullOrWhiteSpace(this.ResultGrid.DataSourceID))
            {
                this.ResultGrid.DataSourceID = this.DataSource.ID;
            }
        }
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.EnsureChildControls();
        }
 
        private void ConfigureView()
        {
            // PageLetterHiddenField
            this.PageLetterHiddenField.ID = "pageLetterHiddenField";
            this.Controls.Add(this.PageLetterHiddenField);
 
            // SearchTextBox
            this.SearchTextBox.ID = "searchTextBox";
            this.Controls.Add(this.SearchTextBox);
 
            if (this.GridSmartSearchType == UI.GridSmartSearchType.XmlHttpPanel)
            {
                // XmlHttpPanel
                this.XmlHttpPanel.ID = "xmlHttpPanel";
                this.XmlHttpPanel.EnableClientScriptEvaluation = true;
                this.XmlHttpPanel.RenderMode = XmlHttpPanelRenderMode.Block;
                this.XmlHttpPanel.ServiceRequest += this.XmlHttpPanel_ServiceRequest;
                this.Controls.Add(this.XmlHttpPanel);
            }
 
            // ResultGrid
            this.ResultGrid.ID = "resultGrid";
            if (this.ShowAlphabeticPager)
            {
                this.ResultGrid.PagerStyle.Mode = GridPagerMode.NumericPages;
                this.ResultGrid.PagerStyle.AlwaysVisible = true;
            }
            this.ResultGrid.ItemCreated += this.ResultGrid_ItemCreated;
            this.ResultGrid.ItemCommand += this.ResultGrid_ItemCommand;
 
            var ajaxLoadingPanel = (RadAjaxLoadingPanel)null;
            // Ajax Loading Panel
            if (this.ShowLoadingPanel)
            {
                ajaxLoadingPanel = new RadAjaxLoadingPanel { ID = "ajaxLoadingPanel" };
                this.Controls.Add(ajaxLoadingPanel);
            }
 
            switch (this.GridSmartSearchType)
            {
                case UI.GridSmartSearchType.XmlHttpPanel:
                    this.XmlHttpPanel.Controls.Add(this.ResultGrid);
                    if (ajaxLoadingPanel != null)
                    {
                        this.XmlHttpPanel.LoadingPanelID = ajaxLoadingPanel.ID;
                    }
                    break;
                case UI.GridSmartSearchType.AjaxManager:
                    this.Controls.Add(this.ResultGrid);
                    this.Page.Load += (sender, e) =>
                    {
                        var mgr = RadAjaxManager.GetCurrent(this.Page);
                        if (mgr != null)
                        {
                            mgr.AjaxSettings.AddAjaxSetting(this.SearchTextBox, this.ResultGrid, ajaxLoadingPanel);
                            mgr.AjaxSettings.AddAjaxSetting(this.ResultGrid, this.ResultGrid, ajaxLoadingPanel);
                        }
                    };
                    break;
                default:
                    this.Controls.Add(this.ResultGrid);
                    break;
            }
 
            this.Controls.Add(this.ControlsContainer);
        }
 
        private void ConfigureDataSource()
        {
            this.DataSource.ID = "dataSource";
 
            if (String.IsNullOrEmpty(this.DataSource.SelectMethod))
            {
                this.DataSource.SelectMethod = "Select";
            }
            if (String.IsNullOrEmpty(this.DataSource.SelectCountMethod))
            {
                this.DataSource.SelectCountMethod = "SelectCount";
            }
            this.DataSource.EnablePaging = true;
            if (String.IsNullOrWhiteSpace(this.DataSource.TypeName))
            {
                this.DataSource.TypeName = typeof(SampleGridSmartSearchDataSource).FullName;
            }
            this.DataSource.SelectParameters.Add(new Parameter("query", DbType.String) { ConvertEmptyStringToNull = true });
            this.DataSource.SelectParameters.Add(new Parameter("pageLetter", DbType.String) { ConvertEmptyStringToNull = true });
            this.DataSource.Selecting += this.DataSource_Selecting;
 
            this.Controls.Add(this.DataSource);
        }
    }

 

 

I attached screenshots before and after postback.

Could you help me somebody please?

Thanks
Vlad

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Aug 2013, 06:27 PM
Hello Vlad,

I would first recommend that you check whether there is a datasource assigned to the detail tables. Then if the problem still persists I will have to ask that you open a regular support ticket with a simple, runnable project demonstrating the problem.

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.
Tags
Grid
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or