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

save raddock state in Database

1 Answer 112 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Roukaya
Top achievements
Rank 2
Roukaya asked on 01 Jun 2012, 09:05 AM
hello all ,
i want a sample example to know how to save state of raddock and Radzone in database (set and get state into and from database ) , not in cookies like used in telerik help documentation (this one )
Is there any sample project to do that ???

thanks in advance

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Jun 2012, 03:41 PM
Hi Roukaya,

Try the following code snippet to save and load state of RadDock in database.

C#:
private List<DockState> CurrentDockStates
        {
            get
            {
                //Get saved state string from the database - set it to dockState variable for example
                string dockStatesFromDB = "";
                _conn.Open();
                SqlCommand command = new SqlCommand("select State from States where id='" + _userID + "' ", _conn);
                dockStatesFromDB = command.ExecuteScalar().ToString();
                _conn.Close();
                List<DockState> _currentDockStates = new List<DockState>();
                string[] stringStates = dockStatesFromDB.Split('|');
                foreach (string stringState in stringStates)
                {
                    if (stringState.Trim() != string.Empty)
                    {
                        _currentDockStates.Add(DockState.Deserialize(stringState));
                    }
                }
                return _currentDockStates;
            }
        }
 
 
protected void RadDockLayout1_SaveDockLayout(object sender, DockLayoutEventArgs e)
        {
            List<DockState> stateList = RadDockLayout1.GetRegisteredDocksState();
            StringBuilder serializedList = new StringBuilder();
            int i = 0;
            while (i < stateList.Count)
            {
                serializedList.Append(stateList[i].ToString());
                serializedList.Append("|");
                i++;
            }
            string dockState = serializedList.ToString();
            if (dockState.Trim() != String.Empty)
            {
                _conn.Open();
                SqlCommand command = new SqlCommand(String.Format("update States set State='{0}' where id='" + _userID + "'", dockState), _conn);
                command.ExecuteNonQuery();
                _conn.Close();
            }
        }
protected void RadDockLayout1_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;
            }
        }

I tried this based on the following code libraries. Please have a look into them.

Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel
Save DockState in DataBase using RadAjaxManager

Regards,
Princy.
Tags
Dock
Asked by
Roukaya
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or