- <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="vs03BindTreeview.WebForm1" %>
- <%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
- <HTML>
- <HEAD>
- <title>WebForm1</title>
- <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
- <meta name="CODE_LANGUAGE" Content="C#">
- <meta name="vs_defaultClientScript" content="JavaScript">
- <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
- <script language="javascript" type="text/javascript">
- function tree_oncheck(tree)
- {
- var node=tree.getTreeNode(tree.clickedNodeIndex);
- var Pchecked=tree.getTreeNode(tree.clickedNodeIndex).getAttribute("checked");
- setcheck(node,Pchecked); //级连选择
- setParentCheck(node,Pchecked);
- document.all.checkedID.value="";
- document.all.checkedNodeData.value="";
- FindCheckedFromNode(TreeView1);
- }
- //设置子节点选中
- function setcheck(node,Pc)
- {
- var i;
- var ChildNode=new Array();
- ChildNode=node.getChildren();
- if(parseInt(ChildNode.length)==0)
- return;
- else
- {
- for(i=0;i<ChildNode.length;i++)
- {
- var cNode;
- cNode=ChildNode[i];
- if(parseInt(cNode.getChildren().length)!=0)
- setcheck(cNode,Pc);
- cNode.setAttribute("Checked",Pc);
- }
- }
- }
- function setParentCheck(node,pc)
- {
- if(pc==true)
- {
- var pnode = node.getParent();
- if (pnode!=null)
- {
- pnode.setAttribute("Checked",pc);
- setParentCheck(pnode,pc);
- }
- }
- }
- //获取所有节点状态
- function FindCheckedFromNode(node)
- {
- var i = 0;
- var nodes = new Array();
- nodes = node.getChildren();
- for (i = 0; i < nodes.length; i++)
- {
- var cNode;
- cNode=nodes[i];
- if (cNode.getAttribute("Checked"))
- {
- //添加选中节点
- var objID = document.getElementById("checkedID");
- var objNodeData = document.getElementById("checkedNodeData");
- if (objID && cNode.getAttribute("ID")!='')
- {
- objID.value += cNode.getAttribute("ID");
- objID.value += '|';
- objNodeData.value+=cNode.getAttribute("NodeData");
- objNodeData.value+='|';
- }
- }
- if (parseInt(cNode.getChildren().length) != 0 )
- {
- FindCheckedFromNode(cNode);
- }
- }
- }
- </script>
- </HEAD>
- <body MS_POSITIONING="GridLayout">
- <form id="Form1" method="post" runat="server">
- <FONT face="宋体">
- <iewc:TreeView id="TreeView1" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 96px"
- runat="server" Width="216px"></iewc:TreeView>
- <asp:Label id="Label4" style="Z-INDEX: 111; LEFT: 640px; POSITION: absolute; TOP: 104px" runat="server">ID</asp:Label>
- <asp:Label id="Label3" style="Z-INDEX: 110; LEFT: 520px; POSITION: absolute; TOP: 104px" runat="server">名称</asp:Label>
- <asp:ListBox id="ListBox2" style="Z-INDEX: 107; LEFT: 488px; POSITION: absolute; TOP: 128px"
- runat="server" Width="104px" Height="264px"></asp:ListBox>
- <asp:ListBox id="ListBox1" style="Z-INDEX: 106; LEFT: 608px; POSITION: absolute; TOP: 128px"
- runat="server" Width="112px" Height="264px"></asp:ListBox>
- <asp:Button id="btnGetValue" style="Z-INDEX: 105; LEFT: 480px; POSITION: absolute; TOP: 64px"
- runat="server" Text="得到哦选中的值" Width="112px"></asp:Button><INPUT id="checkedNodeData" style="Z-INDEX: 104; LEFT: 360px; WIDTH: 344px; POSITION: absolute; TOP: 16px; HEIGHT: 22px"
- type="hidden" size="52" runat="server"><INPUT style="Z-INDEX: 103; LEFT: 16px; WIDTH: 312px; POSITION: absolute; TOP: 16px; HEIGHT: 22px"
- type="hidden" id="checkedID" size="46" runat="server">
- <asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute; TOP: 56px" runat="server"
- Text="读取树结构"></asp:Button></FONT>
- </form>
- </body>
- </HTML>