請問大家是怎么實現的,我不會

解决方案 »

  1.   

    只能给个简单的代码给你看看,复杂的没研究过。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <body>
    <h3>一个简单树的展示</h3>
    <form id="form1" runat="server">
    <asp:TreeView ID="SampleTreeView" runat="server"  ShowLines=true Enabled="true">
    <Nodes>
        <asp:TreeNode Value="个人电脑" NavigateUrl="PC.aspx" Text="个人电脑" Target="Content" Expanded="True">
            <asp:TreeNode Value="硬件" NavigateUrl="hardware.aspx" Text="硬件" Target="Content">
                <asp:TreeNode Value="CPU" NavigateUrl="cpu.aspx" Text="CPU" Target="Content" />
                <asp:TreeNode Value="内存" NavigateUrl="memory.aspx" Text="内存" Target="Content" />
            </asp:TreeNode>
            <asp:TreeNode Value="软件" NavigateUrl="software.aspx" Text="软件" Target="Content" />
        </asp:TreeNode>
    </Nodes>
    </asp:TreeView>
    </form>
    </body>
    </html>
      

  2.   

    父窗口  弹出 showModalDialog窗口哦<script type="text/javascript">
    function ShowDialog(sURL, obj, iWidth, iHeight)
            {
            var oDialog = showModalDialog(sURL, obj, "dialogWidth:" + iWidth.toString() + "px;dialogHeight:" + iHeight.toString() + "px;help:no;scroll:yes;status:yes");
            return oDialog;
            }
    </script><asp:TextBox ID="txtValue" runat="server" CssClass="FormBase" style="width:220px;"></asp:TextBox><input id="btn" type="button" class="ManagerButton" onclick="ShowDialog('子窗口的URL.aspx', window.document, 550, 300);" />
    子窗口<script type="text/javascript">
            function ClickDialog(value)
            {
                window.dialogArguments.getElementById("txtValue").value = value;//将值返回到父窗口的TextBox控件上
                window.close();
            }
        </script><a href="#" onclick="ClickDialog('<%= %>')">选定</a>你treeview在子项上绑定一个onclick 就可以了
      

  3.   

    我写了个例子.能实现你的要求.你自己看吧父窗体:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    // <!CDATA[function btnTest_onclick() {
       var val = window.showModalDialog("Default4.aspx","","Status:No;DialogWidth:450px;DialogHeight:350px;help:no");
       if(val != null)
       {
           document.getElementById("Text1").value = val;
       }
       
    }
    // ]]>
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <br />
            <input id="Text1" type="text" />
            <input id="Button1" type="button" value="open" onclick="btnTest_onclick()" />
            &nbsp;&nbsp;</div>
            <br />
            &nbsp;
        </form>
    </body>
    </html>
    子窗体Default4.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title><base target="_self">
    </head><body>
        <form id="form1" runat="server">
        <div>
            &nbsp;<asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">
            
            <Nodes> 
                    <asp:TreeNode Text="1" Value="1" > 
                        <asp:TreeNode Text="2" Value="2" > </asp:TreeNode> 
                    </asp:TreeNode> 
                    <asp:TreeNode Text="2" Value="2"> 
                        <asp:TreeNode Text="8" Value="8"> 
                            <asp:TreeNode Text="6" Value="6" > </asp:TreeNode> 
                            <asp:TreeNode Text="7" Value="7"> </asp:TreeNode> 
                            <asp:TreeNode Text="9" Value="9"> </asp:TreeNode> 
                        </asp:TreeNode> 
                    </asp:TreeNode> 
                    <asp:TreeNode Text="3" Value="3"> </asp:TreeNode> 
                    <asp:TreeNode Text="4" Value="4"> </asp:TreeNode> 
                    <asp:TreeNode Text="5" Value="5"> </asp:TreeNode> 
                </Nodes> 
            </asp:TreeView>
            </div>
        </form>
    </body>
    </html>Default4.aspx.cs:using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "js", "<script>returnValue ='"+this.TreeView1.SelectedValue+"';window.close();</script>");
        }
    }
      

  4.   

    最好别用selectedchanged事件。每次需要postback下
    用下面方法:
    父亲窗口:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       
    </head>
    <body>
     <script language="javascript" type="text/javascript">
        <!--
        //**************
        function getvalue(returnvalue)
        {
            document.getElementById("<%=TextBox1.ClientID %>").value =  returnvalue;
        }
        //-->
        </script>
        <form id="form1" runat="server">
        <div>
            <input id="Button1" type="button" value="打开"  onclick="window.open('test.aspx','test','height=100, width=400');"/>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        </div>
        </form>
    </body>
    </html>子窗口:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>无标题页</title>
        <script language="javascript" type="text/javascript"> 
        <!-- 
        function test(Text,Value) 
        { 
    //返回Text和value,自己决定
            window.opener.getvalue(Text + "||" + Value);
            //
            window.close();
        } 
        //--> 
        </script>   
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TreeView ID="tvControl" runat="server" ShowLines="true">
               
            </asp:TreeView>
        </div>
        </form>
    </body>
    </html>后台代码:
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    CreateNode(this.tvControl);
                }
            }
            private void CreateNode(TreeView m_tree)
            {
                for (int i = 0; i < 5; i++)
                {
                    TreeNode node = new TreeNode();
                    node.Text = "中国" + i.ToString();
                    node.Value = i.ToString();
                    node.NavigateUrl = "javascript:test('" + node.Text + "','" + node.Value + "');";
                    m_tree.Nodes.Add(node);
                }
            }
    在父亲窗口结果显示为:
    中国0||0
    中国1||1
    ........