Hi,
Use this Script code:
<script language="javascript">
function TVIndexChanged()
{
ChangeText( 'node changed' );
}
function TVNodeExpand()
{
ChangeText( 'onexpand' );
}
function TVNodeCollapse()
{
ChangeText( 'oncollapse' );
}
function TVDoubleClick()
{
ChangeText( 'dblclick' );
}
function TVRightClick()
{
var tree = GetTreeHandle();
var treenode;
if ( null == tree || undefined == tree )
return;
treenode = tree.getTreeNode( event.treeNodeIndex );
if ( null == treenode || undefined == treenode )
return;
// Cause the tree node that was
// right-clicked on to become the
// selected node.
tree.selectedNodeIndex = event.treeNodeIndex;
ChangeText( 'oncontextmenu' );
}
// Simply changes the information
// in the display text boxes to
// demonstrate how to obtain meta-data
// from the selected node's
// NodeData property on the client.
//
function ChangeText( eventName )
{
var treeNode = GetSelectedNode();
if ( null == treeNode || undefined == treeNode )
{
return;
}
var nodeData =
treeNode.getAttribute( 'nodeData' ).split( ';' );
var id = GetKeyValue( 'SomeId' );
var name = GetKeyValue( 'Name' );
document.getElementById( 'txtEvent' ).value =
eventName;
document.getElementById( 'txtId' ).value = id;
document.getElementById( 'txtName' ).value = name;
}
// Gets the value of the searchKey
// from the NodeData of a TreeNode.
//
function GetKeyValue( searchKey )
{
// Get a handle to the selected TreeNode.
var treenode = GetSelectedNode();
// Validate the node handle.
if ( null == treenode || undefined == treenode )
return null;
// Get the node's NodeData property's value.
var nodeDataAry = treenode.getAttribute( 'nodeData' );
if ( null == nodeDataAry || undefined == nodeDataAry )
return null;
nodeDataAry = nodeDataAry.split( ';' );
if ( null == nodeDataAry || undefined == nodeDataAry ||
0 >= nodeDataAry.length )
return null;
var count = 0;
var returnValue = null;
while ( count < nodeDataAry.length )
{
var workingItem = nodeDataAry[ count ];
if ( 0 >= workingItem.length )
{
count++;
continue;
}
// Split the string into its key value pairs.
var kv = workingItem.split( '=' );
if ( 1 >= kv.length )
{
count++;
continue;
}
var key = kv[ 0 ];
var kValue = kv[ 1 ];
if ( key != searchKey )
{
count++;
continue;
}
returnValue = kValue;
break;
}
return returnValue;
}
// Gets a handle to the TreeView.
//
function GetTreeHandle()
{
var tree;
var treeName = 'tvControl';
// Get a handle to the TreeView.
tree = document.getElementById( treeName );
if ( null == tree || undefined == tree )
return null;
return tree;
}
// Gets a handle to the TreeView's selected node.
//
function GetSelectedNode()
{
var tree = GetTreeHandle();
var treeNode;
if ( null == tree || undefined == tree )
return null;
treeNode = tree.getTreeNode( tree.selectedNodeIndex );
if ( null == treeNode || undefined == treeNode )
return null;
return treeNode;
}
</script>
You may refer this link for complete example:http://www.codeproject.com/Articles/10722/ASP-NET-TreeView-Control-the-Client-s-Browser
Thanks,
Prabhu Kiran Bommareddy
Bhupender.Yadav, if this helps please login to Mark As Answer. | Alert Moderator