Asp.net 如何从数据库创建动态Aspxmenu

Asp.net 如何从数据库创建动态Aspxmenu,asp.net,linq,linq-to-xml,asp.net-3.5,devexpress,Asp.net,Linq,Linq To Xml,Asp.net 3.5,Devexpress,**我在C#.*上工作,我想开发asp.net应用程序,它包含菜单,但菜单项应该从数据库生成。我的意图是,管理员只需对数据库进行操作,就可以更改菜单项,而无需对前端进行任何更改 ** ** 下面是我的SQL脚本: USE [Northwind] GO /****** Object: Table [dbo].[Security_Module_Menu] Script Date: 08/05/2010 12:56:02 ******/ SET ANSI_NULLS ON GO SET QUO

**我在C#.*上工作,我想开发asp.net应用程序,它包含菜单,但菜单项应该从数据库生成。我的意图是,管理员只需对数据库进行操作,就可以更改菜单项,而无需对前端进行任何更改

**

**

下面是我的SQL脚本:

USE [Northwind]
GO
/****** Object:  Table [dbo].[Security_Module_Menu]    Script Date: 08/05/2010 12:56:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Security_Module_Menu](
    [Menu_ID] [int] NOT NULL,
    [ParentID] [int] NULL,
    [Menu_Name] [nvarchar](500) NULL,
    [Menu_Description] [nvarchar](500) NULL,
    [Menu_Type] [tinyint] NULL,
    [Tree_Level] [tinyint] NULL,
    [Target_URL] [nvarchar](200) NULL,
    [Image_URL] [nvarchar](200) NULL,
    [ToolTips] [nvarchar](50) NULL,
    [Has_Charge] [bit] NULL,
    [Is_Active] [bit] NULL,
    [Active_Date] [smalldatetime] NULL,
    [Record_Status] [tinyint] NULL,
    [Record_Action_Type] [tinyint] NULL,
 CONSTRAINT [PK_Security_Module_Menu] PRIMARY KEY CLUSTERED 
(
    [Menu_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
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (1, 0, N'Form', N'Form', 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (2, 0, N'Home', N'Home', 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (3, 0, N'About', N'About', 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (4, 1, N'Background', N'Background', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (5, 1, N'Detail', N'Detail', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (6, 3, N'FAQ', N'FAQ', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (7, 3, N'Forum', N'Forum', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (8, 3, N'ContactUs', N'ContactUs', 1, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (9, 2, N'Report_User', N'Report_User', 2, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (10, 2, N'Report_Login', N'Report_Login', 2, 2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (11, 5, N'Admin_Detail', N'Admin_Detail', 1, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
INSERT [dbo].[Security_Module_Menu] ([Menu_ID], [ParentID], [Menu_Name], [Menu_Description], [Menu_Type], [Tree_Level], [Target_URL], [Image_URL], [ToolTips], [Has_Charge], [Is_Active], [Active_Date], [Record_Status], [Record_Action_Type]) VALUES (12, 5, N'User_Detail', N'User_Detail', 1, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)


Menu_Type=1=Form
Menu_Type=2=Report

ParentID=0=MainMenuItem

Tree_Level=1=MainMenuItem.
Tree_Level=2=SubMenuItem.
Tree_Level=3=Sub-SubMenuItem.
在服务器端,AspxMenu如何与XML文件绑定 1)使用Linq创建XML文件。 2) 然后我需要将此文件与AspxMenu绑定。

使用Linq我想创建如下所示的.xml文件:

 XElement xml = new XElement("MyMenu",
                  from c in db.Security_Module_Menus
                  where (c.ParentID == 0)
                  orderby c.Menu_ID
                  select new XElement("Item",
                            new XAttribute("Text", c.Menu_Name), new XAttribute("NavigateUrl",c.Target_URL)


                            )
                  );
**Fill AspxMenu like bellow:**
            XmlDataSource1.DataFile = @"C:\contacts.xml";
        XmlDataSource1.XPath = "MyMenu/Item";
我需要帮助创建XML文件。请帮助我根据以下条件创建XML文件

    Menu_Type=1=Form
    Menu_Type=2=Report

    ParentID=0=MainMenuItem

    Tree_Level=1=MainMenuItem.
    Tree_Level=2=SubMenuItem.
    Tree_Level=3=Sub-SubMenuItem.

按照设计,ASPxMenu仅支持通过其DataSourceID和DataSource属性绑定到层次数据源(实现IHierarchicalDataSource接口的数据源,例如XmlDataSource、SiteMapDataSource)

如果需要将ASPxMenu控件绑定到数据表,则需要一些额外的编码

我们发布了一个教程,说明如何根据数据库信息动态创建ASPxMenu控件:

本教程是附在以下问题上的项目的简化版本:

您是否在应用程序中实现了任何类型的角色?不,我不想使用这些角色。没有权限的人无法查看菜单项。为此,我想为菜单创建动态菜单,请帮助我创建Xml文件
 XElement xml = new XElement("MyMenu",
                  from c in db.Security_Module_Menus
                  where (c.ParentID == 0)
                  orderby c.Menu_ID
                  select new XElement("Item",
                            new XAttribute("Text", c.Menu_Name), new XAttribute("NavigateUrl",c.Target_URL)


                            )
                  );
**Fill AspxMenu like bellow:**
            XmlDataSource1.DataFile = @"C:\contacts.xml";
        XmlDataSource1.XPath = "MyMenu/Item";
    Menu_Type=1=Form
    Menu_Type=2=Report

    ParentID=0=MainMenuItem

    Tree_Level=1=MainMenuItem.
    Tree_Level=2=SubMenuItem.
    Tree_Level=3=Sub-SubMenuItem.