首页 新闻 搜索 专区 学院

如何使用linq to sql 动态加载TreeView数据????

0
[已关闭问题] 关闭于 2012-06-18 14:07

USE [BookStores]
GO
/****** 对象:  Table [dbo].[SYS_ORG_INFO]    脚本日期: 06/14/2012 17:03:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SYS_ORG_INFO](
 [RECORD_ID] [int] IDENTITY(1,1) NOT NULL,
 [ORG_TYPE] [varchar](30) COLLATE Chinese_PRC_CI_AS NOT NULL,
 [ORG_CODE] [varchar](30) COLLATE Chinese_PRC_CI_AS NOT NULL,
 [ORG_NAME] [varchar](100) COLLATE Chinese_PRC_CI_AS NOT NULL,
 [ORG_LEVEL] [int] NOT NULL,
 [PARENT_ID] [int] NOT NULL,
 [PARENT_ID_TREE] [varchar](100) COLLATE Chinese_PRC_CI_AS NOT NULL,
 [SORT_NUM] [int] NULL,
 CONSTRAINT [PK_SYS_ORG_INFO] PRIMARY KEY CLUSTERED
(
 [RECORD_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'记录ID,为表主键' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'RECORD_ID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组织机构类型' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'ORG_TYPE'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组织机构代码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'ORG_CODE'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组织机构名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'ORG_NAME'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组织机构级别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'ORG_LEVEL'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'父级ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'PARENT_ID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'所有父级ID列表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'PARENT_ID_TREE'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'排序号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO', @level2type=N'COLUMN',@level2name=N'SORT_NUM'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'组织机构信息表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SYS_ORG_INFO'

下面是我写的一个动态获取TreeView的方法;还是不能获取到数据的,当sId=8时,var sysinfo = sysorgs.Where(u => u.PARENT_ID == sId); 已经没有符合条件的数据了 报了一个枚举未生成任何结果错误,不知道该如何处理好 请大家指教

 private void GetTreeView(int R_ID,TreeNode pnode)
            {
                var sysorgs = db.SYS_ORG_INFO.OrderBy(p => p.ORG_NAME).Where(u => u.PARENT_ID == R_ID);
                foreach (var item in sysorgs)
                {
                    TreeNode node = new TreeNode();
                    int sId = Convert.ToInt32(item.RECORD_ID);
                    string sName = item.ORG_NAME;
                    node.Text = sName;
                    node.Value = sId.ToString();
                    if (pnode == null)
                    {
                        node.ImageUrl = "~/images/base.gif";
                        node.SelectAction = TreeNodeSelectAction.Expand;
                        tvList.CheckedNodes.Add(node);
                        GetTreeView(sId, node);
                    }
                    else
                    {
                        var sysinfo = sysorgs.Where(u => u.PARENT_ID == sId);
                        foreach (var sys in sysinfo)
                        {
                            node.ImageUrl = "~/images/doc_close.png";
                            node.NavigateUrl = "WebTreeView_Edit.aspx?RECORD_ID=" + sId;
                        }
                        node.ImageUrl = "~/images/doc_now.png";
                        node.NavigateUrl = "WebTreeView_Edit.aspx?RECORD_ID=" + sId;
                        pnode.ChildNodes.Add(node);
                        GetTreeView(sId, pnode);
                    }

                }
              
            }

有效的数据是可以获取到的,就是没显示出来郁闷啊 哪个帮我提供个小例子啊 谢谢啦

问题补充:

不知道怎么回事 这里不能回复想帮助我的人 抱歉!!!节点可以添加到TreeView上 的 还望 能给个简单的案例

mengqiaofa的主页 mengqiaofa | 菜鸟二级 | 园豆:227
提问于:2012-06-14 17:13
< >
分享
所有回答(2)
0

你的数据部分没细看,但你的C#代码不是很好,但也没发现什么问题。

 

你可以先查下是否能真的获取到有效的树状数据。

无之无 | 园豆:5085 (大侠五级) | 2012-06-14 17:32
0

没看到完整代码啊,节点是否添加到TreeView上了?

飞浪 | 园豆:243 (菜鸟二级) | 2012-06-15 10:56
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册