http://www.astreeview.com/astreeviewdemo/astreeviewdemo1.aspx
選擇節點:
<script type="text/javascript"> //選擇節點 OnNodeSelectedScript="nodeSelectHandler(elem);" function nodeSelectHandler(elem){ var val = "selected node:" + elem.parentNode.getAttribute("treeNodeValue"); var vals=elem.parentNode.getAttribute("treeNodeValue"); var valt=elem.innerHTML;//獲取顯示的值//注:塗聚文 document.getElementById("<%=divConsole.ClientID %>").innerHTML += (">>" + val + "<br />"); document.getElementById("<%=TextBox1.ClientID %>").value = vals; document.getElementById("<%=TextBox2.ClientID %>").value = valt; } //parameter must be "elem" function addedHandler( elem ){ document.getElementById( "<%=divConsole.ClientID %>" ).innerHTML += ( ">>edit completed. [Node]" + elem.getAttribute("treeNodeValue") + "<br />" ); } //parameter must be "elem" function editedHandler( elem ){ document.getElementById( "<%=divConsole.ClientID %>" ).innerHTML += ( ">>edit completed. [Node]" + elem.getAttribute("treeNodeValue") + "<br />" ); } //parameter must be "val" function deletedHandler( val ){ document.getElementById( "<%=divConsole.ClientID %>" ).innerHTML += ( ">>delete completed. [Node]" + val + "<br />" ); } //elem is the LI element of each node var displayNodeFunc = function( elem ){ document.getElementById( "<%=divConsole.ClientID %>" ).innerHTML += ( ">>[Node]" + elem.getAttribute("treeNodeValue") + " [Parent]:" + elem.parentNode.parentNode.getAttribute("treeNodeValue") + " [CheckState]:" + elem.getAttribute("checkedState") + "<br />" ); } </script>
<ct:ASTreeView ID="astvMyTree" runat="server" BasePath="~/Javascript/astreeview/" DataTableRootNodeValue="0" EnableRoot="false" EnableNodeSelection="true" EnableCheckbox="false" EnableDragDrop="true" EnableTreeLines="true" EnableNodeIcon="true" EnableCustomizedNodeIcon="false" AutoPostBack="false" EnableDebugMode="false" OnNodeSelectedScript="nodeSelectHandler(elem);" EnableContextMenu="true" EnableAjaxOnEditDelete="true" EditNodeProvider="~/ASTreeViewRenameNodeHandler.aspx" DeleteNodeProvider="~/ASTreeViewDeleteNodeProvider.aspx" AddNodeProvider="~/ASTreeViewDemo3.aspx" AdditionalAddRequestParameters="{'t':'ajaxAdd'}" AddNodePromptDefaultValue="New Node" AddNodePromptMessage="Hello, please add a new node:" AddNodeDataValueProvider="return prompt('new ndoe? under:' + elem.getAttribute('treeNodeValue'),'new node name');" OnNodeAddedScript="addedHandler(elem)" OnNodeEditedScript="editedHandler(elem)" OnNodeDeletedScript="deletedHandler(val)" OnOnSelectedNodeChanged="astvMyTree_OnSelectedNodeChanged" />
/// <summary> /// initial controls, bind you events etc. here /// </summary> private void InitializeComponent() { //獲取值 添加右鍵菜單進行編輯 //注:塗聚文 //this.astvMyTree.ContextMenu.MenuItems.Add(new ASContextMenuItem("獲取 current value", "alert('current value:' + " + this.astvMyTree.ContextMenuClientID + ".getSelectedItem().parentNode.getAttribute('treeNodeValue')" + ");return false;", "otherevent")); this.astvMyTree.ContextMenu.MenuItems.Add(new ASContextMenuItem("獲取 current value", "alert('current value:' + " + this.astvMyTree.ContextMenuClientID + ".getSelectedItem().parentNode.getAttribute('treeNodeValue')" + ");window.location.href ='ASTreeViewEdit.aspx?EditNodeValues='+" + this.astvMyTree.ContextMenuClientID + ".getSelectedItem().parentNode.getAttribute('treeNodeValue')" + ";", "otherevent")); this.astvMyTree.ContextMenu.MenuItems.Add(new ASContextMenuItem("獲取 current text", "alert('current text:' + " + this.astvMyTree.ContextMenuClientID + ".getSelectedItem().innerHTML" + ");return false;", "otherevent")); }