FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 2946|回复: 2
打印 上一主题 下一主题

tree自己连接数据库,加载tree 怎么不行?

[复制链接]
跳转到指定楼层
楼主
发表于 2013-9-13 17:28:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
private void LoadData()
        {
            // 模拟从数据库返回数据表
            db.getConnectString();
            db.Open();


            DataSet ds = new DataSet();

            string sql= "select * from plus_file order by id";
            ds = db.getDataSet(sql);
            ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["PId"]);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                if (row.IsNull("PId"))
                {
                    TreeNode node = new TreeNode();
                    node.Text = row["name"].ToString();
                    node.Expanded = true;
                    treeMenu.Nodes.Add(node);

                    ResolveSubTree(row, node);
                }
            }
            db.Close();
        }
出现“不能启用此约束,因为不是所有的值都具有相应的父值”
把代码改为
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["PId"],false);
tree不能加载为空

推荐
 楼主| 发表于 2013-9-16 09:40:56 | 只看该作者
哪位大侠能帮助解决一下吗?
板凳
发表于 2013-10-1 03:56:18 | 只看该作者
因为你最前面的父节点不是NULL
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-9-28 07:26 , Processed in 0.044126 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表