如何从 xml 文件填充 AspxMenu
在我的页面上,我有两个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
try this out