Remote Scripting to dynamically add the leaves to a Tree Control

 

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
January 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

 

This Demo uses remote scripting to dynamically add the leaves. i.e. it loads the root items first then loads the child items when you expand the parent item.  Note:that with the remote scripting samples there is a hard-coded path to the relevant support files, this will have to be changed appropriately for people to get the demos to work on their own system. 

First Page--RSTreeView.htm

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>TreeView using Remote Scripting</TITLE>
</HEAD>
<BODY>
<!-- Author: Adrian Forbes -->
<script language="JavaScript" src="../_scriptlibrary/rs.htm"></script>
<script language="JavaScript">RSEnableRemoteScripting("../_scriptlibrary");</script>

<OBJECT ID="tvwTree" WIDTH=300 HEIGHT=276
CLASSID="CLSID:0713E8A2-850A-101B-AFC0-4210102A8DA7">
<PARAM NAME="_ExtentX" VALUE="7938">
<PARAM NAME="_ExtentY" VALUE="7303">
<PARAM NAME="_Version" VALUE="327682">
<PARAM NAME="Indentation" VALUE="0">
<PARAM NAME="LabelEdit" VALUE="1">
<PARAM NAME="LineStyle" VALUE="1">
<PARAM NAME="Style" VALUE="7">
<PARAM NAME="Appearance" VALUE="1">
</OBJECT>
<p>
<input type=BUTTON onClick="SubmitNode();" value="Select" id=BUTTON1 name=BUTTON1>
</p>
<form name=frmTree action="TreeControlTarget.asp" method=GET>
<input type=HIDDEN name=txtSelected>
</form>

<script language=VBScript>
strDBPage = "RSDatabase.asp"
tvwChild = 4

sub window_onLoad
    LoadParents
end sub

function LoadParents

    set objRS = RSExecute(strDBPage ,"GetDBParents")
    sRS = objRS.return_value
    aRows = Split(sRS, Chr(13))

    tvwTree.Nodes.Clear
   
    for i = 0 to UBound(aRows) - 1
        aFields = Split(aRows(i), ";")
        Set tmpNode = tvwTree.Nodes.Add(, , "P" & aFields(0), aFields(1))
        tvwTree.Nodes.Add tmpNode, tvwChild, , "DUMMY"
    next

end function

Sub tvwTree_Expand(ByVal Node)
dim tmpRS, lHeaderID
dim sOld, sNew

    If Node.Child.Text <> "DUMMY" Then
        exit sub
    end if

    tvwTree.Nodes.Remove Node.Child.Index

    lID = mid(node.Key, 2)
    set objRS = RSExecute(strDBPage ,"GetDBChildren", lID)
    sRS = objRS.return_value
    aRows = Split(sRS, Chr(13))

    for i = 0 to UBound(aRows) - 1
        aFields = Split(aRows(i), ";")
        tvwTree.Nodes.Add Node, tvwChild, "C" & aFields(0), aFields(1)
    next

End Sub

sub SubmitNode
    if document.tvwTree.selecteditem is nothing then
        msgbox "Select an item from the tree"
    else
        document.frmTree.txtSelected.value = document.tvwTree.selecteditem.text
        document.frmTree.submit
    end if
end sub
</script>

</BODY>
</HTML>

Page 2 RSDatabase.asp

<%@ LANGUAGE=VBSCRIPT %>
<%
strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name
%>
<% RSDispatch %>
<!-- Author: Adrian Forbes -->
<!--#INCLUDE FILE="../_ScriptLibrary/rs.asp"-->
<SCRIPT RUNAT=SERVER Language=javascript>
    function Description()
    {
        this.GetDBParents = Function( 'return GetDBParents()' );
        this.GetDBChildren = Function('ID', 'return GetDBChildren(ID)' );
        this.Method1 = Method1;
    }
    public_description = new Description();

function Method1()
{
    return 'Test';
}
</script>

<SCRIPT RUNAT=SERVER Language=VBScript>
    function GetDBParents()

        set objRS = createobject("ADODB.Recordset")
        objRS.Open "select ID, strParent from Parents", strconn
        GetDBParents = objRS.GetString(, , ";")
        objRS.Close
        set objRS.ActiveConnection = nothing
        set objRS = nothing
       
    end function

    function GetDBChildren(ID)

        set objRS = createobject("ADODB.Recordset")
        objRS.Open "select ID, strChild from Children WHERE intParent=" & ID, strconn
        GetDBChildren = objRS.GetString(, , ";")
        objRS.Close
        set objRS.ActiveConnection = nothing
        set objRS = nothing
       
    end function
</SCRIPT>




blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials