I have below javascript function in code-behind file for expand & collapse node:
private void SetActions()
{
String sString =
@"
function SaveTreeState(action)
{
var tree = $find('" + RadTreeView1.ClientID + @"');
if(tree == null) { return; }
var nodes = tree.get_allNodes();
if(action == 'expand')
{
for(var cnt=0; cnt<nodes.length; cnt++)
{
nodes[cnt].expand();
}
}
if(action == 'collapse')
{
for(var cnt=0; cnt<nodes.length; cnt++)
{
nodes[cnt].collapse();
}
}
var expandedNodes = '';
for(var cnt=0; cnt<nodes.length; cnt++)
{
if(nodes[cnt].get_expanded())
{
expandedNodes += nodes[cnt].get_value() + '|';
}
}
SaveCookie('mpnotetreestate',expandedNodes);
}
function SaveCookie(name,value,days) {
if (days) {
if (days>730) {
days=730;
}
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = '; expires='+date.toGMTString();
}
else var expires = '';
document.cookie = name+'='+value+expires+'; path=/';
}
";
ScriptManager.RegisterClientScriptBlock(this, typeof(ViewNotes), "SaveTreeStateBlock", sString, true);
ViewToolBar1.btnExpandAll.Attributes.Add("onclick", "try{SaveTreeState('expand');}catch(err){return;}return false;");
ViewToolBar1.btnCollapseAll.Attributes.Add("onclick", "try{SaveTreeState('collapse');}catch(err){return}return false;");
}
In UI I am using the below:
<cc2:MPTreeView BorderStyle="None" OnNodeDataBound="RadTreeView1_NodeDataBound" OnClientNodeCollapsed="SaveTreeState"
OnClientNodeExpanded="SaveTreeState" ShowLineImages="false" ID="RadTreeView1" runat="server">
<CollapseAnimation Duration="100" Type="None" />
<ExpandAnimation Duration="100" Type="None" />
I am not able to collapse the treeview control on button click nor able to expand ? Could u please suggest.
Thanks
Bikash