Dock Position in the DockZone

3 posts, 0 answers
  1. Evgeniy
    Evgeniy avatar
    17 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2008 Link to this post

    Hi,

    I have table in Database with fields: id, title, text, position.

    Every record in table it is RadDock control.

    I need on load page add RadDock Control in RadZone with position from database.
    I can add RadDock in RadZone, but position RadDock is not position from database.

    How I can make it?

    my aspx file:
    <telerik:RadDockLayout ID="RadDockLayout1" runat="server" OnLoadDockLayout="RadDockLayout1_LoadDockLayout" 
                OnSaveDockLayout="RadDockLayout1_SaveDockLayout" Skin="Vista"
                <div style="float:left;"
                    <telerik:RadDockZone ID="rdZone" runat="server" Height="100%" Skin="Vista" Width="500px"
                    </telerik:RadDockZone> 
                </div> 
    </telerik:RadDockLayout> 

    my cs file:
    protected void Page_Init(object sender, EventArgs e)  
        {  
            if (!IsPostBack)  
            {  
                //data - this is DataSet; da - this is DataAdapter  
                da.Fill(data);  
      
                for (int i = 0; i < data.Rows.Count; i++)  
                {  
                    RadDock dock = CreateRadDock(data[i].Title, data[i].Text, data[i].Id, data[i].Position-1);  
      
                        rdZone.Controls.Add(dock);  
                        ScriptManager.RegisterStartupScript(  
                            dock,  
                            this.GetType(),  
                            "AddDock",  
                            string.Format(@"function _addDock() {{  
                                Sys.Application.remove_load(_addDock);  
                                $find('{1}').dock($find('{0}'));  
                                $find('{0}').doPostBack('DockPositionChanged');  
                                }};  
                                Sys.Application.add_load(_addDock);", dock.ClientID, rdZone.ClientID),  
                            true);  
            }  
            else  
            for (int i = 0; i < CurrentDockStates.Count; i++)  
            {  
                RadDock dock = CreateRadDockFromState(CurrentDockStates[i]);  
                RadDockLayout1.Controls.Add(dock);  
            }  
        }  
     
    private List<DockState> CurrentDockStates 
        { 
            get 
            { 
                List<DockState> _currentDockStates = (List<DockState>)Session["CurrentDockStatesDynamicDocks"]; 
                if (Object.Equals(_currentDockStates, null)) 
                { 
                    _currentDockStates = new List<DockState>(); 
                    Session["CurrentDockStatesDynamicDocks"] = _currentDockStates; 
                } 
                return _currentDockStates; 
            } 
            set 
            { 
                Session["CurrentDockStatesDynamicDocks"] = value; 
            } 
        } 
     
        private RadDock CreateRadDockFromState(DockState state) 
        { 
            RadDock dock = new RadDock(); 
            dock.ID = string.Format("RadDock{0}", state.UniqueName); 
            dock.DefaultCommands = Telerik.Web.UI.Dock.DefaultCommands.ExpandCollapse; 
            dock.Style.Add("padding-bottom", "10px"); 
            dock.ApplyState(state); 
     
            return dock; 
        } 
     
        private RadDock CreateRadDock(string title, string text, int id, int position) 
        { 
            int docksCount = CurrentDockStates.Count; 
     
            RadDock dock = new RadDock(); 
            dock.UniqueName = Guid.NewGuid().ToString(); 
            dock.ID = string.Format("RadDock{0}", dock.UniqueName); 
            dock.Title = title
            dock.Text = text
            dock.Skin = "Vista"
            dock.Style.Add("padding-bottom", "10px"); 
            dock.Collapsed = true
            dock.DefaultCommands = Telerik.Web.UI.Dock.DefaultCommands.ExpandCollapse; 
            dock.Attributes.Add("id", id.ToString()); 
     
            return dock; 
        } 
     
        protected void RadDockLayout1_LoadDockLayout(object sender, DockLayoutEventArgs e) 
        { 
            foreach (DockState state in CurrentDockStates) 
            { 
                e.Positions[state.UniqueName] = state.DockZoneID; 
                e.Indices[state.UniqueName] = state.Index; 
            } 
        } 
        protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e) 
        { 
            CurrentDockStates = RadDockLayout1.GetRegisteredDocksState(); 
        } 

    Thanks!!!!!!!


  2. Petko
    Admin
    Petko avatar
    45 posts

    Posted 02 Dec 2008 Link to this post

    Hello Evgeniy,

    You can see how to save/load dockstate from DB in this forum:
    http://www.telerik.com/community/forums/aspnet-ajax/docking/dynamically-adding-docks-loading-content-from-a-database.aspx
    Check the post of Sophy, where she sent an attached project, that demonstrates how to achieve the desired scenario.
    Hope this helps you.

    Sincerely yours,
    Petko
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. tieu
    tieu avatar
    1 posts
    Member since:
    Dec 2008

    Posted 29 May 2009 Link to this post

    add 1 row to save name of RadDock, 1 row to save name of RadDockZone (want add RadDock when program run)
    When you Load Data in database to Page, you must done:

    //Get Data in database --> add to Table
     DataTable tbl = GetData();

                if (tbl != null && tbl.Rows.Count > 0)
                {
                    foreach (DataRow row in tbl.Rows)
                    {
                        string radDockName = row["Control"].ToString();
                        RadDock radDock = (RadDock)FindControl(radDockName);
                        if (radDock != null)
                        {
                            radDock.UniqueName = row["Control"].ToString();
                            radDock.ID = radDockName;
                            String Zone =ReplaceText(row["LayoutPosition"].ToString());
                            int Index = Convert.ToInt32(row["position"].ToString());
    //if you want drag and drop control :                           
                                radDock.DockHandle = DockHandle.Grip;
                                radDock.DockMode = DockMode.Docked;      
    //if you don't want drag and drop control: set DockHandle = DockHandle.None;          
                           

                            DockState state = new DockState();
                            state.UniqueName = radDockName;
                            state.DockZoneID = row["LayoutPosition"].ToString();
                            state.Index = Index

                            radDock.ApplyState(state);
                        }
                    }
                }
    Hope this helps you.
Back to Top