zoukankan
html css js c++ java
树形结构与父子页数据传递
父页
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
>
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
>
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;
}
}
}
查看全文
相关阅读:
cmd 命令添加防火墙端口
linux 远程 telnet
topshelf 服务启动运行
postfix 邮箱服务器- SPF 防发件人欺骗
linux 只查看目录下文件夹
Android中的颜色设置
thread和runnable
Handler总结
Failed to install Intel HAXM.
Android Studio常见问题总结
原文地址:https://www.cnblogs.com/tongzhenhua/p/166802.html
最新文章
使用YUM安装MySQL 5.5(适用于CentOS6.2/5.8及Fedora 17/16平台)
Java nio socket与as3 socket(粘包解码)连接的应用实例
php简单开启gzip压缩方法(zlib.output_compression)
PHP 5.4 on CentOS/RHEL 7.0, 6.5 and 5.10 via Yum
CentOS下用rinetd做端口转发
Python set
python 深浅拷贝
python字典使用
python字典实现
python 元组
热门文章
python 列表常用方法
python开发第一篇:初识python
Thrift入门之mac下的安装流程
教你一招:win10下JDK的安装与环境变量配置
推荐几款精美耐看的xshell配色方案!
windows bat 批处理 执行 for 循环无法执行?
Windows 查找txt后缀 文件复制
windows 下的 Rsync 同步
Linux 文件格式转码工具
Nginx 站点设置目录列表显示
Copyright © 2011-2022 走看看