Ext.Net 1.x_Ext.Net.TreePanel 选择值回传父页

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:

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;
        }

    }
}
效果:

Ext.Net 1.x_Ext.Net.TreePanel 选择值回传父页_第1张图片

你可能感兴趣的:(Ext.Net 1.x_Ext.Net.TreePanel 选择值回传父页)