树形结构与父子页数据传递

父页

WebPage2.aspx

None.gif < body MS_POSITIONING = " GridLayout " >
None.gif        
< form id = " Form1 "  method = " post "  runat = " server " >
None.gif            
< FONT face = " 宋体 " >< INPUT id = " TB_CFYJ "   type = " text "     name = " TB_CFYJ " >< INPUT  type = " button "  value = " Button "  onclick = " window.open('WebForm1.aspx', '', ''); " ></ FONT >
None.gif        
</ form >
None.gif    
</ body >


WebPage1.aspx

None.gif <% @ Page language = " c# "  Codebehind = " WebForm1.aspx.cs "  AutoEventWireup = " false "  Inherits = " test.WebForm1 "   %>
None.gif
<% @ Register TagPrefix = " iewc "  Namespace = " Microsoft.Web.UI.WebControls "  Assembly = " Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35 "   %>
None.gif
<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.0 Transitional//EN "   >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > WebForm1 </ title >
None.gif        
< meta content = " JavaScript "  name = " vs_defaultClientScript " >
None.gif        
< meta content = " http://schemas.microsoft.com/intellisense/ie5 "  name = " vs_targetSchema " >
None.gif        
< script >
None.gif        function GetAttribute()
// 没用
ExpandedBlockStart.gifContractedBlock.gif
         dot.gif { alert(TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")); }
None.gif           
None.gif        function gg()
// 客户端遍历(有BUG。碰上折起来的结点就会出错)
ExpandedBlockStart.gifContractedBlock.gif
         dot.gif {
InBlock.gif            var AllRootNode
=new Array();
InBlock.gif            AllRootNode
=TreeView1.getChildren();
InBlock.gif            AlertNode(AllRootNode);
InBlock.gif            function AlertNode(NodeArray)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(parseInt(NodeArray.length)==0)
InBlock.gif                    
return;
InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
for(i=0;i<NodeArray.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        var cNode;
InBlock.gif                        cNode
=NodeArray[i];
InBlock.gif                        alert(cNode.getAttribute(
"Text"));
InBlock.gif                        
if(parseInt(cNode.getChildren().length)!=0)
InBlock.gif                            AlertNode(cNode.getChildren());
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
        
None.gif        function addCFYJ()
// For Client回传值
ExpandedBlockStart.gifContractedBlock.gif
         dot.gif {
InBlock.gif            var mys 
= opener.document.all("TB_CFYJ");
InBlock.gif            mys.value
=mys.value+TreeView1.getTreeNode(TreeView1.selectedNodeIndex).getAttribute("Text")
ExpandedBlockEnd.gif        }

None.gif        
None.gif        
</ script >
None.gif    
</ HEAD >
None.gif    
< body MS_POSITIONING = " GridLayout " >
None.gif        
< FONT face = " 宋体 " >
None.gif            
< form id = " Form1 "  method = " post "  runat = " server " >
None.gif                
< INPUT type = " button "  onclick = " addCFYJ() "  value = " client方式 " > // 这里是直接用客户端方式把数据传回去
None.gif
                 < iewc:treeview id = " TreeView1 "  runat = " server " ></ iewc:treeview >
None.gif                
< asp:Button id = " Button1 "  runat = " server "  Text = " 服务器重写js " ></ asp:Button ></ form >
None.gif        
</ FONT >
None.gif    
</ body >
None.gif
</ HTML >
None.gif


WebPage2.cs

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
using  Microsoft.Web.UI.WebControls;
None.gif
using  System.Data.OracleClient;
None.gif
None.gif
namespace  test
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
InBlock.gif        
protected System.Web.UI.HtmlControls.HtmlForm Form1;
InBlock.gif        
protected System.Web.UI.WebControls.Button Button1;
InBlock.gif    
InBlock.gif        DataSet ds;
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            OracleConnection conn
=new OracleConnection("user id=hzzfj;password=hzzfj;data source=hzzfj");
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{                    
InBlock.gif                OracleDataAdapter ad
=new OracleDataAdapter("select * from  dept",conn);
InBlock.gif                ds
=new DataSet();
InBlock.gif                ad.Fill(ds,
"tree");
InBlock.gif                InitTree(TreeView1.Nodes,
"0");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception E)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockEnd.gif            }

InBlock.gif            
finally
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                conn.Close();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//建树的基本思路是:从根节点开始递归调用显示子树 
InBlock.gif
        private void InitTree(TreeNodeCollection Nds,string parentId) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            DataView dv
=new DataView();
InBlock.gif            TreeNode tmpNd;
InBlock.gif            
string intId;
InBlock.gif            dv.Table
=ds.Tables["tree"];
InBlock.gif            dv.RowFilter
="PARENTID="+parentId + "" ;
InBlock.gif            
foreach(DataRowView drv in dv) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                tmpNd
=new TreeNode();
InBlock.gif                tmpNd.ID
=drv["DEPT_ID"].ToString();
InBlock.gif                tmpNd.Text
=drv["DEPT_NAME"].ToString();
InBlock.gif                tmpNd.CheckBox
=true;                
InBlock.gif                
//tmpNd.ImageUrl="../images/"+drv["Icon"].ToString();
InBlock.gif                
//tmpNd.NavigateUrl="../"+drv["Address"].ToString();
InBlock.gif
                Nds.Add(tmpNd);
InBlock.gif                intId
=drv["ParentId"].ToString();
InBlock.gif                InitTree(tmpNd.Nodes,tmpNd.ID);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
string res="";
InBlock.gif        
private void Button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//Response.Write("<script> alert('"+GetAllNodeText(TreeView1.Nodes)+"')</script>");
InBlock.gif
            Response.Write("<script> var mys = opener.document.all('TB_CFYJ');mys.value='"+GetAllNodeText(TreeView1.Nodes)+"';</script>");
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
string GetAllNodeText(TreeNodeCollection tnc)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
foreach(TreeNode node in tnc)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(node.Nodes.Count!=0)
InBlock.gif                    GetAllNodeText(node.Nodes);
InBlock.gif                
if (node.Checked)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    res
+=node.Text + "|";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return res;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/tongzhenhua/archive/2005/06/02/166802.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值