Coolite TreePanel的数据绑定操作

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                BindTree(TreePanel1.Root, 0);
            }
        }

        private void BindTree(Coolite.Ext.Web.TreeNodeCollection nodes, int p)
        {
            DataTable dt = GetByPid(p);

            foreach (DataRow r in dt.Rows)
            {
                Coolite.Ext.Web.TreeNode node = new Coolite.Ext.Web.TreeNode(r["id"].ToString(), r["name"].ToString(), Icon.Add);
                node.Qtip = r["kind"].ToString();
                nodes.Add(node);
                switch (int.Parse(node.Qtip))
                {
                    case 1:
                        if (null !=node.ParentNode)
                        {
                            node.ParentNode.Icon = Icon.Folder;
                        }                       
                        break;
                    case 2:
                        node.Icon = Icon.Accept;
                        break;
                    case 3:                       
                    case 4:
                        node.Icon = Icon.Bell;
                        break;
                    default:
                        break;
                }               

                BindTree(node.Nodes, int.Parse(r["id"].ToString()));
            }
        }

private DataTable GetByPid(int pid)
        {
            DataTable dt = new DataTable("T");

            OracleConnection cnn = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["default"].ConnectionString);
            try
            {
                cnn.Open();

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append("select * from ( ");
                sb.Append("select a.organization_id as id, a.parent_id as pid, a.organization_name as name, 1 as kind from organization a ");
                sb.Append("union all ");
                sb.Append("select b.dynamotor_id+10000 as id, b.organization_id as pid, b.dynamotor_name as name, 2 as kind from DYNAMOTOR b ");
                sb.Append("union all ");
                sb.Append("select c.turbine_id+20000 as id, c.dynamotor_id +10000 as pid, c.turbine_short_name as name, 3 as kind from TURBINE_INFO c ");
                sb.Append("union all ");
                sb.Append("select d.boiler_id+30000 as id, d.dynamotor_id+10000 as pid, d.boiler_short_name as name, 4 as kind from BOILER_INFO d ");
                sb.Append(") ");
                sb.Append("where pid=" + pid.ToString());
                sb.Append(" order by id");

                OracleDataAdapter da = new OracleDataAdapter(sb.ToString(), cnn);

                da.Fill(dt);

            }
            finally
            {
                cnn.Close();
            }

            return dt;
        }

原文:http://hi.baidu.com/38608338/blog/item/918aa01abfe12ff3ae513303.html

你可能感兴趣的:(TreePanel)