This is a migrated thread and some comments may be shown as answers.
Dock Position in the DockZone
2 Answers 90 Views
This is a migrated thread and some comments may be shown as answers.
Evgeniy
Top achievements
Rank 1
Evgeniy asked on 02 Dec 2008, 10:39 AM
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 Answers, 1 is accepted

Sort by
0
Petko
Telerik team
answered on 02 Dec 2008, 12:59 PM
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.
0
tieu
Top achievements
Rank 1
answered on 29 May 2009, 09:39 AM
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.
Tags
Dock
Asked by
Evgeniy
Top achievements
Rank 1
Answers by
Petko
Telerik team
tieu
Top achievements
Rank 1
Share this question
or