Failure: Add RadDock Dynamically from RadGrid button

2 posts, 0 answers
  1. Mc
    Mc avatar
    5 posts
    Member since:
    Jan 2015

    Posted 26 Jan 2015 Link to this post

    I have a RadGrid and I want to use one of the column to dynamically add new RadDock but nothing happened. I created a single asp:Button to test my FederationDetailBtnClick method which add dock correctly but the button from grid failed. Help needed!!!

    aspx file:
    <telerik:RadGrid ID="FederationGrid" runat="server"
            <MasterTableView EnableHierarchyExpandAll="true" AutoGenerateColumns="False" TableLayout="Fixed" DataKeyNames="Id">
                    <telerik:GridBoundColumn DataField="Id" HeaderText="Federation Name" UniqueName="FederationId">
                    <telerik:GridBoundColumn DataField="Status" HeaderText="Status" UniqueName="Status">
                    <telerik:GridButtonColumn HeaderText="Federation Detail" Text="Detail" UniqueName="FederationDetail" ButtonType="PushButton">
        <telerik:RadAjaxPanel ID="RadAjaxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel">
            <telerik:RadDockLayout runat="server" ID="RadDockLayout_Federation"
                <telerik:RadDockZone ID="RadDockZone_Federation" runat="server" Orientation="Horizontal">

    aspx.cs file:
    private List<DockState> CurrentDockStates
                    // Store the info about the added docks in the session.
                    List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesDeployment"];
                    if (Object.Equals(_currentDockStates, null))
                        _currentDockStates = new List<DockState>();
                        Session["CurrentDockStatesDeployment"] = _currentDockStates;
                    return _currentDockStates;
                    Session["CurrentDockStatesDeployment"] = value;
            protected void Page_Load(object sender, EventArgs e)
            protected void FederationGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
                this.federationList = DataModelRequestHandler.GetFederationsAsync(this.environment);
                FederationGrid.DataSource = this.federationList;
            protected void FederationGrid_ItemCreated(object sender, GridItemEventArgs e)
                if (e.Item is GridDataItem)
                    GridDataItem dataitem = (GridDataItem)e.Item;
                    Button btn = (Button)dataitem["FederationDetail"].Controls[0];
                    btn.Click += new EventHandler(FederationDetailBtnClick);
            protected void FederationGrid_ItemDataBound(object sender, GridItemEventArgs e)
                if (e.Item is GridDataItem)
                    GridDataItem dataitem = (GridDataItem)e.Item;
                    Button btn = (Button)dataitem["FederationDetail"].Controls[0];
                    btn.CommandArgument = (e.Item as GridDataItem)["FederationId"].Text;
            protected void RadDockLayout_LoadDockLayout(object sender, DockLayoutEventArgs e)
                // Populate the event args with the state information. The RadDockLayout control
                // will automatically move the docks according that information.
                foreach (DockState state in CurrentDockStates)
                    e.Positions[state.UniqueName] = state.DockZoneID;
                    e.Indices[state.UniqueName] = state.Index;
            protected void RadDockLayout_SaveDockLayout(object sender, DockLayoutEventArgs e)
                CurrentDockStates = RadDockLayout_Federation.GetRegisteredDocksState();
            private void FederationDetailBtnClick(object sender, EventArgs e)
                var btnView = (Button)sender;
                var FederationId = btnView.CommandArgument;
                // Create RadDock
                RadDock dock = this.CreateRadDock(FederationId);
                // Dock it on DockZone
            private RadDock CreateRadDock(string dockTitle)
                RadDock dock = new RadDock();
                dock.DockMode = DockMode.Docked;
                dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
                dock.ID = string.Format("RadDock{0}", dock.UniqueName);
                dock.Title = dockTitle;
                dock.Commands.Add(new DockCloseCommand());
                dock.Commands.Add(new DockExpandCollapseCommand());
                return dock;

  2. Slav
    Slav avatar
    1359 posts

    Posted 29 Jan 2015 Link to this post


    You need to ensure that the FederationDetailBtnClick method, which is an event handler of the click event of the buttons in RadGrid, is property attached. The AutoEventWireup attribute of the Page directive should be set to true for this purpose. You can also set a breakpoint in the FederationDetailBtnClick method and run the page in debug mode to check if the method is executed on each button click.

    Also, if you want to persist the generated docks when a postback occurs, you need to recreate them on Page_Init, before their state is applied. This approach is demonstrated in the following demo:

    You can find attached a sample page that shows both adding a dock when the button in the grid is clicked and persisting all created docks through postback.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top