WebPage2.aspx
<
body MS_POSITIONING
=
"
GridLayout
"
>
< form id = " Form1 " method = " post " runat = " server " >
< FONT face = " 宋体 " >< INPUT id = " TB_CFYJ " type = " text " name = " TB_CFYJ " >< INPUT type = " button " value = " Button " onclick = " window.open('WebForm1.aspx', '', ''); " ></ FONT >
</ form >
</ body >
< form id = " Form1 " method = " post " runat = " server " >
< FONT face = " 宋体 " >< INPUT id = " TB_CFYJ " type = " text " name = " TB_CFYJ " >< INPUT type = " button " value = " Button " onclick = " window.open('WebForm1.aspx', '', ''); " ></ FONT >
</ form >
</ body >
WebPage1.aspx
<%
@ Page language
=
"
c#
"
Codebehind
=
"
WebForm1.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
test.WebForm1
"
%>
<% @ Register TagPrefix = " iewc " Namespace = " Microsoft.Web.UI.WebControls " Assembly = " Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " %>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > WebForm1 </ title >
< meta content = " JavaScript " name = " vs_defaultClientScript " >
< meta content = " http://schemas.microsoft.com/intellisense/ie5 " name = " vs_targetSchema " >
< script >
function GetAttribute() // 没用
{ alert(TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")); }
function gg() // 客户端遍历(有BUG。碰上折起来的结点就会出错)
{
var AllRootNode=new Array();
AllRootNode=TreeView1.getChildren();
AlertNode(AllRootNode);
function AlertNode(NodeArray)
{
if(parseInt(NodeArray.length)==0)
return;
else
{
for(i=0;i<NodeArray.length;i++)
{
var cNode;
cNode=NodeArray[i];
alert(cNode.getAttribute("Text"));
if(parseInt(cNode.getChildren().length)!=0)
AlertNode(cNode.getChildren());
}
}
}
}
function addCFYJ() // For Client回传值
{
var mys = opener.document.all("TB_CFYJ");
mys.value=mys.value+TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")
}
</ script >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< FONT face = " 宋体 " >
< form id = " Form1 " method = " post " runat = " server " >
< INPUT type = " button " onclick = " addCFYJ() " value = " client方式 " > // 这里是直接用客户端方式把数据传回去
< iewc:treeview id = " TreeView1 " runat = " server " ></ iewc:treeview >
< asp:Button id = " Button1 " runat = " server " Text = " 服务器重写js " ></ asp:Button ></ form >
</ FONT >
</ body >
</ HTML >
<% @ Register TagPrefix = " iewc " Namespace = " Microsoft.Web.UI.WebControls " Assembly = " Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " %>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > WebForm1 </ title >
< meta content = " JavaScript " name = " vs_defaultClientScript " >
< meta content = " http://schemas.microsoft.com/intellisense/ie5 " name = " vs_targetSchema " >
< script >
function GetAttribute() // 没用
{ alert(TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")); }
function gg() // 客户端遍历(有BUG。碰上折起来的结点就会出错)
{
var AllRootNode=new Array();
AllRootNode=TreeView1.getChildren();
AlertNode(AllRootNode);
function AlertNode(NodeArray)
{
if(parseInt(NodeArray.length)==0)
return;
else
{
for(i=0;i<NodeArray.length;i++)
{
var cNode;
cNode=NodeArray[i];
alert(cNode.getAttribute("Text"));
if(parseInt(cNode.getChildren().length)!=0)
AlertNode(cNode.getChildren());
}
}
}
}
function addCFYJ() // For Client回传值
{
var mys = opener.document.all("TB_CFYJ");
mys.value=mys.value+TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")
}
</ script >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< FONT face = " 宋体 " >
< form id = " Form1 " method = " post " runat = " server " >
< INPUT type = " button " onclick = " addCFYJ() " value = " client方式 " > // 这里是直接用客户端方式把数据传回去
< iewc:treeview id = " TreeView1 " runat = " server " ></ iewc:treeview >
< asp:Button id = " Button1 " runat = " server " Text = " 服务器重写js " ></ asp:Button ></ form >
</ FONT >
</ body >
</ HTML >
WebPage2.cs
using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
using System.Data.OracleClient;
namespace test
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Button Button1;
DataSet ds;
private void Page_Load(object sender, System.EventArgs e)
{
OracleConnection conn=new OracleConnection("user id=hzzfj;password=hzzfj;data source=hzzfj");
try
{
OracleDataAdapter ad=new OracleDataAdapter("select * from dept",conn);
ds=new DataSet();
ad.Fill(ds,"tree");
InitTree(TreeView1.Nodes,"0");
}
catch(Exception E)
{
}
finally
{
conn.Close();
}
}
//建树的基本思路是:从根节点开始递归调用显示子树
private void InitTree(TreeNodeCollection Nds,string parentId)
{
DataView dv=new DataView();
TreeNode tmpNd;
string intId;
dv.Table=ds.Tables["tree"];
dv.RowFilter="PARENTID="+parentId + "" ;
foreach(DataRowView drv in dv)
{
tmpNd=new TreeNode();
tmpNd.ID=drv["DEPT_ID"].ToString();
tmpNd.Text=drv["DEPT_NAME"].ToString();
tmpNd.CheckBox=true;
//tmpNd.ImageUrl="../images/"+drv["Icon"].ToString();
//tmpNd.NavigateUrl="../"+drv["Address"].ToString();
Nds.Add(tmpNd);
intId=drv["ParentId"].ToString();
InitTree(tmpNd.Nodes,tmpNd.ID);
}
}
string res="";
private void Button1_Click(object sender, System.EventArgs e)
{
//Response.Write("<script> alert('"+GetAllNodeText(TreeView1.Nodes)+"')</script>");
Response.Write("<script> var mys = opener.document.all('TB_CFYJ');mys.value='"+GetAllNodeText(TreeView1.Nodes)+"';</script>");
}
string GetAllNodeText(TreeNodeCollection tnc)
{
foreach(TreeNode node in tnc)
{
if(node.Nodes.Count!=0)
GetAllNodeText(node.Nodes);
if (node.Checked)
{
res+=node.Text + "|";
}
}
return res;
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
using System.Data.OracleClient;
namespace test
{
/**//// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Button Button1;
DataSet ds;
private void Page_Load(object sender, System.EventArgs e)
{
OracleConnection conn=new OracleConnection("user id=hzzfj;password=hzzfj;data source=hzzfj");
try
{
OracleDataAdapter ad=new OracleDataAdapter("select * from dept",conn);
ds=new DataSet();
ad.Fill(ds,"tree");
InitTree(TreeView1.Nodes,"0");
}
catch(Exception E)
{
}
finally
{
conn.Close();
}
}
//建树的基本思路是:从根节点开始递归调用显示子树
private void InitTree(TreeNodeCollection Nds,string parentId)
{
DataView dv=new DataView();
TreeNode tmpNd;
string intId;
dv.Table=ds.Tables["tree"];
dv.RowFilter="PARENTID="+parentId + "" ;
foreach(DataRowView drv in dv)
{
tmpNd=new TreeNode();
tmpNd.ID=drv["DEPT_ID"].ToString();
tmpNd.Text=drv["DEPT_NAME"].ToString();
tmpNd.CheckBox=true;
//tmpNd.ImageUrl="../images/"+drv["Icon"].ToString();
//tmpNd.NavigateUrl="../"+drv["Address"].ToString();
Nds.Add(tmpNd);
intId=drv["ParentId"].ToString();
InitTree(tmpNd.Nodes,tmpNd.ID);
}
}
string res="";
private void Button1_Click(object sender, System.EventArgs e)
{
//Response.Write("<script> alert('"+GetAllNodeText(TreeView1.Nodes)+"')</script>");
Response.Write("<script> var mys = opener.document.all('TB_CFYJ');mys.value='"+GetAllNodeText(TreeView1.Nodes)+"';</script>");
}
string GetAllNodeText(TreeNodeCollection tnc)
{
foreach(TreeNode node in tnc)
{
if(node.Nodes.Count!=0)
GetAllNodeText(node.Nodes);
if (node.Checked)
{
res+=node.Text + "|";
}
}
return res;
}
}
}