raddock

2 posts, 1 answers
  1. Sigma
    Sigma avatar
    87 posts
    Member since:
    Apr 2012

    Posted 24 Aug 2012 Link to this post

    hi,,
    how to save and load state of raddock in database..

    thanks..
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Aug 2012 Link to this post

    Hi,

    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;
                }
            }
    Also take a look into the following code libraries.
    Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel
    Save DockState in DataBase using RadAjaxManager

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top