ASP.NET Tree_DB - Step by step configuration -
server side implementation

The data sent to the server is processed in the cs_TreeEvents.aspx.cs file.
Because we are using the AJAX Page control, the page class has to
be derived from the OboutInc.oboutAJAXPage class:
    public class cs_TreeEvents : OboutInc.oboutAJAXPage
                        
This is explained with more details here.

The Constructor

In the constructor of the page class, we declare a Tree_DB object and set its properties
(because the fields from our database are different from the default ones)
    public cs_TreeEvents()
    {
        oTreeDB = new TreeDB();           

        // declaring the connection string:
        oTreeDB.ConnectionString = 
            "Server=.\\SQLEXPRESS;AttachDBFilename=|DataDirectory|TreeNodes.mdf;
			Database=TreeNodes;Trusted_Connection=Yes;";
        
        // declaring the table name:            
        oTreeDB.TableName = "treeview";
        oTreeDB.ProviderName = "System.Data.SqlClient";

        // declaring the name and the type of the fields from the database
        oTreeDB.Fields[TreeDB.StandardFields.ID].DbFieldName = "NodeID";
        oTreeDB.Fields[TreeDB.StandardFields.ParentID].DbFieldName = "ParentID";
        oTreeDB.Fields[TreeDB.StandardFields.HTMLValue].DbFieldName = "NodeHTML";
        oTreeDB.Fields[TreeDB.StandardFields.Icon].DbFieldName = "NodeIcon";
        oTreeDB.Fields[TreeDB.StandardFields.Level].SetProperties("NodeLevel", "numeric");
        oTreeDB.Fields[TreeDB.StandardFields.Expanded].SetProperties("Expanded", "numeric");
    }
                        

Methods

On the client-side we added a number of parameters for each event we want to handle.
We also specified in the post function the name of the server-side method which will implement
the server-side processing for each event.

The arguments of these methods will be the parameters created with the AddParam function.


For adding nodes:
    
    public string OnAddNode(string parentId, string childId, string textOrHTML, string expanded, 
		string image, string subTreeURL)
    {        
        oTreeDB.Fields[TreeDB.StandardFields.ParentID].Value = parentId;
        oTreeDB.Fields[TreeDB.StandardFields.ID].Value = childId;
        oTreeDB.Fields[TreeDB.StandardFields.HTMLValue].Value = textOrHTML;
        oTreeDB.Fields[TreeDB.StandardFields.Expanded].Value = expanded;
        oTreeDB.Fields[TreeDB.StandardFields.Icon].Value = image;
        
        // process the information and returning the result:
        string sResult = oTreeDB.ExecuteEvent(TreeDB.EventTypes.Add);
		
        if (sResult != "1") { throw new Exception(sResult); }
		
        return sResult;		      
    }
                        

For editing nodes:
    public string OnNodeEdit(string id, string text, string prevText)
    {        
        // specify the type of action that the Tree_DB component should take:
        oTreeDB.EventType = TreeDB.EventTypes.Edit;
		
        // prepare tha data for the Tree_DB object
        oTreeDB.Fields[TreeDB.StandardFields.ID].Value = id;
        oTreeDB.Fields[TreeDB.StandardFields.HTMLValue].Value = text;
		
        // process the information and returning the result:
        string sResult = oTreeDB.ExecuteEvent();
		
        if (sResult != "1") { throw new Exception(sResult); }
		
        return sResult;		      
    }
                        

For removing nodes:
    public string OnRemoveNode(string id)
    {
        // specify the type of action that the Tree_DB component should take:
        oTreeDB.EventType = TreeDB.EventTypes.Remove;
		
        // prepare tha data for the Tree_DB object - the data should be sent using this format:
        oTreeDB.Fields[TreeDB.StandardFields.ID].Value = id;
		
        // process the information and returning the result:
        string sResult = oTreeDB.ExecuteEvent();
		
        if (sResult != "1") { throw new Exception(sResult); }
		
        return sResult;		      
    }
                        

For updating the level of the nodes:
    public string OnNodeDrop(string src, string dst)
    {        
        // specify the type of action that the Tree_DB component should take:
        oTreeDB.EventType = TreeDB.EventTypes.UpdateLevel;
		
        // prepare tha data for the Tree_DB object - the data should be sent using this format:
        oTreeDB.Fields[TreeDB.StandardFields.ID].Value = src;
        oTreeDB.Fields[TreeDB.StandardFields.ParentID].Value = dst;
		
        // process the information and returning the result:
        string sResult = oTreeDB.ExecuteEvent();
		
        if (sResult != "1") { throw new Exception(sResult); }
		
        return sResult;	      
    }
                        
Read more about implementing the server-side methods for the AJAX Page control.


For any questions send us a support request. See How-To and Help page

Next

« Back to summary           Client Side