简体   繁体   English

如何使用EntityDataSource填充TreeView

[英]How to populate a TreeView using EntityDataSource

I use MS SQL, EF 4 and C#. 我使用MS SQL,EF 4和C#。

I have a table in SQL fro "Categories" and I need populate a TreeView in my Asp.net page. 我在SQL中有一个来自“类别”的表,我需要在Asp.net页中填充一个TreeView。

My question are: 我的问题是:

  • 1 - How can i populate the TreeView? 1-如何填充TreeView?
  • 2 - How can i use the TreeView to modify the hierarchy of my Categories? 2-如何使用TreeView修改我的类别的层次结构?

NOTE: I use "hierarchyid" SQL Columns! 注意:我使用“ hierarchyid” SQL列!

Thanks guys for your help! 谢谢大家帮助!

    CREATE TABLE dbo.CmsCategories
(
    CategoryId          int             NOT NULL    IDENTITY (0,1)  -- Seed = 0 and Increment= 1
        CONSTRAINT PK_CmsCategories_CategoryId PRIMARY KEY,
    Title               nvarchar(40)    NOT NULL,
    MetaDescription     nvarchar(160)   NOT NULL,
    MetaKeyword         nvarchar(128)   NOT NULL,
    Summary             nvarchar(256)   NOT NULL,
    IsPublished         bit             NOT NULL
        CONSTRAINT DF_CmsCategories_IsPublished DEFAULT 1,  
    CategoryNode        hierarchyid     NOT NULL,
    CategoryNodeLevel AS CategoryNode.GetLevel()        
);

Unfortunately, EF4 doesn't support HierarchyId (yet). 不幸的是,EF4还不支持HierarchyId。 So in this case, your best bet would probably be to have a stored procedure that deals with your hierarchy and return a result set back to EF that EF4 can turn into a collection of user-defined complex type that can then be bound directly to the treeview control. 因此,在这种情况下,最好的选择是拥有一个处理层次结构的存储过程,并将结果集返回给EF,以便EF4可以将其转换为用户定义的复杂类型的集合,然后可以将其直接绑定到EF4。树视图控件。

If you plan to update your hierarchy in the database, I would use the same approach: call a stored procedure from EF to update your hierarchy in the database. 如果您打算更新数据库中的层次结构,我将使用相同的方法:从EF调用存储过程来更新数据库中的层次结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM