如何从 xml 文件填充 AspxMenu

发布于 2024-09-14 01:46:53 字数 3318 浏览 2 评论 0原文

在我的页面上,我有两个AspxMenu。单击主菜单对应的值将显示在子菜单

XML语法:

<Demo>
<ClientCompanyId CompanyId="1">
<MyMenu>
<module Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False">
<menu Text="Forms" MID="1-1" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="LookUp" MID="1-3" ParentID="1" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-3">
</Leaf>
<submenu Text="Bank Branch" MID="1-4" ParentID="1" MenuDescription="" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="BO Category" MID="1-5" ParentID="4" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-5">
</Leaf>
</submenu>
</menu>
<menu Text="Reports" MID="1-2" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="Cheque Type" MID="1-6" ParentID="2" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-6">
</Leaf>
<Leaf Text="Stock Exchange" MID="1-7" ParentID="2" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-7">
</Leaf>
</menu>
</module>
</MyMenu>
</ClientCompanyId></Demo>

MasterMenu填充并单击事件:

 XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            //XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            var q = from c in loaded.Descendants("module")
                    where (int)c.Attribute("ModuleID") > 0
                    select new
                    {
                        Text = (string)c.Attribute("Text"),
                        ModID = (string)c.Attribute("ModID"),
                        ModuleID = (int)c.Attribute("ModuleID"),
                        MenuType = (int)c.Attribute("MenuType"),
                        Perm = (bool)c.Attribute("Perm")
                    };


            foreach (var name in q)
            {
                ASPxMasterMenu.RootItem.Items.Add(name.Text,name.ModuleID.ToString());


            } 

点击主菜单:

var r= ASPxMenu1.SelectedItem.Name;

            XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            var q = from c in loaded.Descendants("menu")
                    where (int)c.Attribute("ModuleID") == Convert.ToInt32(ASPxMenu1.SelectedItem.Name)
                    select new
                    {
                        Text = (string)c.Attribute("Text"),
                        ModID = (string)c.Attribute("ModID"),
                        ModuleID = (int)c.Attribute("ModuleID"),
                        MenuType = (int)c.Attribute("MenuType"),
                        Perm = (bool)c.Attribute("Perm")
                    };


            foreach (var name in q)
            {
                AspxChildMenu.RootItem.Items.Add(name.Text);


            } 

在我的XML中的module标签下menu标签包含几个叶子和子菜单< /strong>标签我想用这些值填充我的AspxChildMenu。如何做?

On my page I have two AspxMenu.Click on Master Menu correspondent value will show on Child menu

XML syntax:

<Demo>
<ClientCompanyId CompanyId="1">
<MyMenu>
<module Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False">
<menu Text="Forms" MID="1-1" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="LookUp" MID="1-3" ParentID="1" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-3">
</Leaf>
<submenu Text="Bank Branch" MID="1-4" ParentID="1" MenuDescription="" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="BO Category" MID="1-5" ParentID="4" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-5">
</Leaf>
</submenu>
</menu>
<menu Text="Reports" MID="1-2" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="Cheque Type" MID="1-6" ParentID="2" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-6">
</Leaf>
<Leaf Text="Stock Exchange" MID="1-7" ParentID="2" MenuDescription="" ModuleID="1" MenuType="0" Perm="False" LeafNode="true" TargetUrl="" ModuleMenuID="1-7">
</Leaf>
</menu>
</module>
</MyMenu>
</ClientCompanyId></Demo>

MasterMenu fill and click Event:

 XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            //XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            var q = from c in loaded.Descendants("module")
                    where (int)c.Attribute("ModuleID") > 0
                    select new
                    {
                        Text = (string)c.Attribute("Text"),
                        ModID = (string)c.Attribute("ModID"),
                        ModuleID = (int)c.Attribute("ModuleID"),
                        MenuType = (int)c.Attribute("MenuType"),
                        Perm = (bool)c.Attribute("Perm")
                    };


            foreach (var name in q)
            {
                ASPxMasterMenu.RootItem.Items.Add(name.Text,name.ModuleID.ToString());


            } 

click on master Menu:

var r= ASPxMenu1.SelectedItem.Name;

            XDocument loaded = XDocument.Load(@"C:\Menu_Settings.xml");

            var q = from c in loaded.Descendants("menu")
                    where (int)c.Attribute("ModuleID") == Convert.ToInt32(ASPxMenu1.SelectedItem.Name)
                    select new
                    {
                        Text = (string)c.Attribute("Text"),
                        ModID = (string)c.Attribute("ModID"),
                        ModuleID = (int)c.Attribute("ModuleID"),
                        MenuType = (int)c.Attribute("MenuType"),
                        Perm = (bool)c.Attribute("Perm")
                    };


            foreach (var name in q)
            {
                AspxChildMenu.RootItem.Items.Add(name.Text);


            } 

in my XML under the module tag menu tag contains several leaf and submenutag i want to fill my AspxChildMenu by those values.How to ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜血缘 2024-09-21 01:46:53

试试这个

var menu = from c in loaded.Descendants("menu")
                     where c.Attribute("ModuleID").Value == "1"
                     select c;

        var q = from c in menu.Descendants()
                where c.Name == "Leaf" || c.Name == "submenu"
                select new
                {
                    Text = (string)c.Attribute("Text"),
                    ModID = (string)c.Attribute("ModID"),
                    ModuleID = (int)c.Attribute("ModuleID"),
                    MenuType = (int)c.Attribute("MenuType"),
                    Perm = (bool)c.Attribute("Perm")
                };

try this out

var menu = from c in loaded.Descendants("menu")
                     where c.Attribute("ModuleID").Value == "1"
                     select c;

        var q = from c in menu.Descendants()
                where c.Name == "Leaf" || c.Name == "submenu"
                select new
                {
                    Text = (string)c.Attribute("Text"),
                    ModID = (string)c.Attribute("ModID"),
                    ModuleID = (int)c.Attribute("ModuleID"),
                    MenuType = (int)c.Attribute("MenuType"),
                    Perm = (bool)c.Attribute("Perm")
                };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文