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",
开发者_Python百科 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! :)
hopefully the link below can solve ur problem : http://www.mikeborozdin.com/post/ASPNET-TreeView-and-Checkboxes.aspx
Here is my solution, but maybe doesn't fit with your case. but I like to share this with you. the idea is very simple, I set Tooltip
of Treeview node
with the Value
and use that in my js
code.
var node = new TreeNode
{
Text = "SOME_TEXT",
Value = "VALUE",
ToolTip = "VALUE"
};
Then is js:
$('.treeview input[type=checkbox]').on('change', function () {
var value = $(this).attr('title'); // this will get you the VALUE
});
精彩评论