以编程方式绑定菜单控件 [英] programatically bind menu control

查看:91
本文介绍了以编程方式绑定菜单控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案


您去了:
DataTable结构:
记住您的表结构应类似于:
Hi,
Here you go:
DataTable Structure :
Remember your table structure should be like:
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


这篇关于以编程方式绑定菜单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆