网站地图    收藏   

主页 > 前端 > css教程 >

TreePanel 选择值回传父页 - html/css语言栏目:htm

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] HTML:[html] %@ Page Language=C# AutoEventWireup=true CodeBehind=Property2.aspx.cs Inherits=DzPlatForm.CRM.Property.Property2 %%@ Register Assembly=Ext.Net Namespace=Ext.Net......

HTML:


[html]  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Property2.aspx.cs" Inherits="DzPlatForm.CRM.Property.Property2" %> 
 
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> 
<!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> 
    <link rel="stylesheet" type="text/css" href="../../resources/css/main.css" /> 
    <script type="text/javascript"> 
        //树 单击取值主键FID 
        function ClickNode(node) { 
            if (node.hasChildNodes()) { //判断是否有子节点 
 
            } 
            else { 
 
                var t = node.attributes.text; 
                var v = node.attributes.id; 
 
                parent.txtPropertyName_2.setValue(t); 
                parent.txtProperty_2.setValue(v); 
                parent.WinCustClass.hide(); 
            } 
        } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
 <ext:ResourceManager ID="ResourceManager1" runat="server" /> 
    <ext:TreePanel ID="TreePanel1" runat="server" Icon="ApplicationHome" Height="450" 
        Shadow="None" UseArrows="true" AutoScroll="true" Animate="true" EnableDD="true" 
        ContainerScroll="true" RootVisible="false"> 
        <Root> 
        </Root> 
    </ext:TreePanel> 
    </form> 
</body> 
</html> 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Property2.aspx.cs" Inherits="DzPlatForm.CRM.Property.Property2" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!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>
    <link rel="stylesheet" type="text/css" href="../../resources/css/main.css" />
    <script type="text/javascript">
        //树 单击取值主键FID
        function ClickNode(node) {
            if (node.hasChildNodes()) { //判断是否有子节点

            }
            else {

                var t = node.attributes.text;
                var v = node.attributes.id;

                parent.txtPropertyName_2.setValue(t);
                parent.txtProperty_2.setValue(v);
                parent.WinCustClass.hide();
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
 <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:TreePanel ID="TreePanel1" runat="server" Icon="ApplicationHome" Height="450"
        Shadow="None" UseArrows="true" AutoScroll="true" Animate="true" EnableDD="true"
        ContainerScroll="true" RootVisible="false">
        <Root>
        </Root>
    </ext:TreePanel>
    </form>
</body>
</html>

CS:


[csharp]  using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Data; 
using System.Data.SqlClient; 
using Ext.Net; 
using DzPlatForm.DBUtility; 
 
namespace DzPlatForm.CRM.Property 

    public partial class Property2 : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!X.IsAjaxRequest) 
            { 
                //读取来源数据表  
                string strSql = string.Format("SELECT [Id],[ParentId],[Name] FROM [CustomerClass]"); 
                DataTable dt = new DataTable(); 
                dt = SqlHelper.ExecuteDataset(SqlHelper.conn, CommandType.Text, strSql).Tables[0]; 
                if (dt.Rows.Count > 0) 
                { 
                    this.BuildTree(this.TreePanel1.Root, dt); 
                } 
                else 
                { 
 
                    Notification.Show(new NotificationConfig 
                    { 
                        Title = "提示", 
                        Icon = Icon.Information, 
                        Html = "没有取得数据" 
                    }); 
                } 
 
            } 
        } 
        /// <summary>  
        /// TreePanel  
        /// </summary>  
        /// <param name="allData"></param>  
        /// <returns></returns>  
        public TreeNode BindTreePanel(DataTable allData) 
        { 
            TreeNode topNode = new TreeNode(); 
            topNode.NodeID = "0"; 
            topNode.Text = "Root"; 
 
            if (allData != null && allData.Rows.Count > 0) 
            { 
                DataRow[] items = allData.Select("ParentId=-1"); 
                if (items != null && items.Length > 0) 
                { 
                    DataSet ds = new DataSet(); 
                    ds.Merge(items); 
                    DataTable SourseTable = ds.Tables[0]; 
 
                    for (int i = 0; i < SourseTable.Rows.Count; i++) 
                    { 
                        TreeNode Tvn = new TreeNode(); 
                        Tvn.Expandable = ThreeStateBool.True; 
                        Tvn.NodeID = SourseTable.Rows[i]["Id"].ToString(); 
                        Tvn.Text = SourseTable.Rows[i]["Name"].ToString(); 
                        DataRow[] isChildNode = allData.Select("ParentId=" + SourseTable.Rows[i]["Id"].ToString()); 
                        if (isChildNode.Length > 0) 
                        { 
                            Tvn.Icon = Icon.FolderGo; 
 
                        } 
                        else 
                        { 
                            Tvn.Leaf = true; 
                            Tvn.Icon = Icon.ApplicationViewColumns; 
                        } 
 
                        BindSubTreePanel(Tvn, allData, SourseTable.Rows[i]["Id"].ToString()); 
                        Tvn.Listeners.Click.Handler = "ClickNode(node)"; 
                        topNode.Nodes.Add(Tvn); 
 
                    } 
                } 
            } 
            return topNode; 
        } 
        /// <summary>  
        ///   
        /// </summary>  
        /// <param name="TrNode"></param>  
        /// <param name="allData"></param>  
        /// <param name="parentID"></param>  
        private void BindSubTreePanel(TreeNode TrNode, DataTable allData, string parentID) 
        { 
            DataRow[] items = allData.Select("ParentId=" + parentID); 
 
            if (items != null && items.Length > 0) 
            { 
                DataSet ds = new DataSet(); 
                ds.Merge(items); 
                DataTable dt = ds.Tables[0]; 
                for (int i = 0; i < dt.Rows.Count; i++) 
                { 
                    TreeNode Tvn = new TreeNode(); 
                    Tvn.Icon = Icon.Note; 
                    Tvn.NodeID = dt.Rows[i]["Id"].ToString(); 
                    Tvn.Text = dt.Rows[i]["Name"].ToString(); 
                    DataRow[] isChildNode = allData.Select("ParentId=" + dt.Rows[i]["Id"].ToString()); 
                    if (isChildNode.Length > 0) 
                    { 
                        Tvn.Icon = Icon.FolderGo; 
 
                    } 
                    else 
                    { 
                        Tvn.Leaf = true; 
                        Tvn.Icon = Icon.ApplicationViewColumns; 
 
                    } 
 
                    BindSubTreePanel(Tvn, allData, dt.Rows[i]["Id"].ToString()); 
                    Tvn.Listeners.Click.Handler = "ClickNode(node)"; 
                    TrNode.Nodes.Add(Tvn); 
                } 
            } 
 
        } 
        private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection root, DataTable dt) 
        { 
            root.Add(this.BindTreePanel(dt)); 
            return root; 
        } 
 
    } 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using Ext.Net;
using DzPlatForm.DBUtility;

namespace DzPlatForm.CRM.Property
{
    public partial class Property2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                //读取来源数据表
                string strSql = string.Format("SELECT [Id],[ParentId],[Name] FROM [CustomerClass]");
                DataTable dt = new DataTable();
                dt = SqlHelper.ExecuteDataset(SqlHelper.conn, CommandType.Text, strSql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    this.BuildTree(this.TreePanel1.Root, dt);
                }
                else
                {

                    Notification.Show(new NotificationConfig
                    {
                        Title = "提示",
                        Icon = Icon.Information,
                        Html = "没有取得数据"
                    });
                }

            }
        }
        /// <summary>
        /// TreePanel
        /// </summary>
        /// <param name="allData"></param>
        /// <returns></returns>
        public TreeNode BindTreePanel(DataTable allData)
        {
            TreeNode topNode = new TreeNode();
            topNode.NodeID = "0";
            topNode.Text = "Root";

            if (allData != null && allData.Rows.Count > 0)
            {
                DataRow[] items = allData.Select("ParentId=-1");
                if (items != null && items.Length > 0)
                {
                    DataSet ds = new DataSet();
                    ds.Merge(items);
                    DataTable SourseTable = ds.Tables[0];

                    for (int i = 0; i < SourseTable.Rows.Count; i++)
                    {
                        TreeNode Tvn = new TreeNode();
                        Tvn.Expandable = ThreeStateBool.True;
                        Tvn.NodeID = SourseTable.Rows[i]["Id"].ToString();
                        Tvn.Text = SourseTable.Rows[i]["Name"].ToString();
                        DataRow[] isChildNode = allData.Select("ParentId=" + SourseTable.Rows[i]["Id"].ToString());
                        if (isChildNode.Length > 0)
                        {
                            Tvn.Icon = Icon.FolderGo;

                        }
                        else
                        {
                            Tvn.Leaf = true;
                            Tvn.Icon = Icon.ApplicationViewColumns;
                        }

                        BindSubTreePanel(Tvn, allData, SourseTable.Rows[i]["Id"].ToString());
                        Tvn.Listeners.Click.Handler = "ClickNode(node)";
                        topNode.Nodes.Add(Tvn);

                    }
                }
            }
            return topNode;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="TrNode"></param>
        /// <param name="allData"></param>
        /// <param name="parentID"></param>
        private void BindSubTreePanel(TreeNode TrNode, DataTable allData, string parentID)
        {
            DataRow[] items = allData.Select("ParentId=" + parentID);

            if (items != null && items.Length > 0)
            {
                DataSet ds = new DataSet();
                ds.Merge(items);
                DataTable dt = ds.Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeNode Tvn = new TreeNode();
                    Tvn.Icon = Icon.Note;
                    Tvn.NodeID = dt.Rows[i]["Id"].ToString();
                    Tvn.Text = dt.Rows[i]["Name"].ToString();
                    DataRow[] isChildNode = allData.Select("ParentId=" + dt.Rows[i]["Id"].ToString());
                    if (isChildNode.Length > 0)
                    {
                        Tvn.Icon = Icon.FolderGo;

                    }
                    else
                    {
                        Tvn.Leaf = true;
                        Tvn.Icon = Icon.ApplicationViewColumns;

                    }

                    BindSubTreePanel(Tvn, allData, dt.Rows[i]["Id"].ToString());
                    Tvn.Listeners.Click.Handler = "ClickNode(node)";
                    TrNode.Nodes.Add(Tvn);
                }
            }

        }
        private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection root, DataTable dt)
        {
            root.Add(this.BindTreePanel(dt));
            return root;
        }

    }
}效果:

 \
 


 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论