Hi all,
How to obtain value of selected node of asp.net treeview from javascript?
I have tree:
<asp:TreeView ID="dtDivisions" runat="server" onclick="OnDivisionChecked(event);" ShowCheckBoxes="All" ShowLines="true">
</asp:TreeView>
I fill it using next method:
private static void BindTreeViewNode(TreeView control, TreeNode parentNode)
{
int parentId = parentNode == null ? -1 : Convert.ToInt32(parentNode.Value);
var list = DictionariesDAO.GetListByParentId(DictionaryType.Divisions, parentId);
foreach (var item in list)
{
TreeNode node = new TreeNode(item.Name, item.Id.ToString())
{
ImageUrl = item.HasChilds ? "js/dtree/img/folder.gif" : "js/dtree/img/page.gif",
NavigateUrl = item.Id.ToString(),
SelectAction = TreeNodeSelectAction.None
};
if (parentNode == null)
{
node.ImageUrl = "js/dtree/img/base.gif";
control.Nodes.Add(node);
}
else
{
parentNode.ChildNodes.Add(node);
}
if (item.HasChilds)
{
BindTreeViewNode(control, node);
}
}
}
I need in OnDivisionChecked javascript method obtain value of selected node. I try to put it in NavigationUrl property of TreeView but without success.
Ex:
var snode = document.getElementById(TreeNode.id.replace('CheckBox', '').replace('dtDivisionsn', 'dtDivisionst'));
document.getElementById('ctl00_PlaceHolderMain_hidDivisionsId').value = snode.href;
Please help! :)