问题描述
HI Friends,
我正在尝试解决问题,但无法解决.请帮助我..
问题是.....
我想绑定还包含子类别的菜单控件.
注意-表中只有一列包含类别和子子类别.基于另一列"Catg_Order"来解决此问题.
HI Friends,
I am trying to solve a problem but i am not able to solve that.Please help me..
problem is that.....
I want to bind menu control that also contain sub categoryes.
NOTE- Only one column in a table contain category and sub subcategory. Based upon another column "Catg_Order" to solve this problem.
推荐答案
ID | Description | ParentID | NavigateURL
前端编码:
要绑定菜单项,只需调用此函数:
Front-End Coding:
For binding the menu item just call this function:
//This function will bind the top menu item
private void AddTopMenuItems(DataTable menuData)
{
DataView view = new DataView(menuData);
view.RowFilter = "ParentID IS NULL";
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["Text"].ToString(), row["MenuID"].ToString());
menuBar.Items.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem);
}
}
//This code is used to recursively add child menu items by filtering by ParentID
private void AddChildMenuItems(DataTable menuData, MenuItem parentMenuItem)
{
DataView view = new DataView(menuData);
view.RowFilter = "ParentID=" + parentMenuItem.Value;
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["Text"].ToString(), row["MenuID"].ToString());
newMenuItem.NavigateUrl = row["NavigateUrl"].ToString();
parentMenuItem.ChildItems.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem);
}
}
这是一篇有关数据库绑定菜单的好文章:
使用数据库绑定菜单控件 [ ^ ]
您也可以在此处查看以获取更多帮助.
希望对您有所帮助.
祝一切顺利.
--Amit
Here is a nice article on binding menu from database:
Binding Menu Control With Database[^]
You can also view here for further assistance.
Hope this may help you.
All the best.
--Amit
这篇关于以编程方式绑定菜单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!