动态菜单创建.... asp.net [英] Dynamic Menu Creation.........asp.net

查看:53
本文介绍了动态菜单创建.... asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平菜单,其中包含项目(HR,PRODUCTION,QC)

现在,当我单击HR时.我希望在左侧生成一个垂直菜单,其中包含与HR相关的子项....

同样,当我单击Production和QC时,它应显示其各自的子项....

为此,我在母版页上放置了两个菜单.....水平菜单从站点地图中填充,但如何根据单击的选项填充垂直菜单......

在此先感谢......

I have a horizoatal menu with items( HR , PRODUCTION , QC )

now when i click on HR.. i want a vertical menu to be generated on the left side with HR related child items.......

Similarly, when i click on Production and QC, it should display its respective child items....

For this i have put two menu on master page.....Horizoantal menu populates from sitemap but how can i populate vertical menu based on the option i click...........

Thanks in advance......

推荐答案

如果您将代码发布在这里,那会很好.随便....
在此示例中,我从XML文件中检索数据,创建数据集,然后将菜单项添加到Menu Control.
It would be fine if you post your code here. any way....
Here in this example i retrieve data from XML file, create a dataset then adding menu items to Menu Control.
<asp:menu id="MenuContent" runat="server" orientation="Vertical" cssclass="menustyle" xmlns:asp="#unknown">
</asp:Menu></asp:menu>


protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                EnableMenu();
            }
        }

        protected void EnableMenu()
        {
            DataSet ds = new DataSet();
            DataRowView drPView;
            DataRowView drCView;
            ds.ReadXml(ConfigurationSettings.AppSettings["XMLFile"].ToString());
            DataView dvParent = new DataView(ds.Tables[0]);
            DataView dvChild = new DataView(ds.Tables[1]);
            MenuItem oParentMenuItem = new MenuItem();
            MenuItem oChildMenuItem = new MenuItem();

            for (int i = 0; i < dvParent.Count; i++)
            {
                drPView = dvParent[i];
                oParentMenuItem = new MenuItem(drPView.Row.ItemArray["MenuCaption"].ToString(), drPView.Row.ItemArray["ParentId"].ToString());
                MenuContent.Items.Add(oParentMenuItem);
                dvChild.RowFilter = "ParentId=" + drPView.Row.ItemArray["ParentId"].ToString();
                for (int i = 0; i &lt; dvChild.Count; i++)
                {
                  drCView = dvChild[i];
                  oChildMenuItem  = new MenuItem(drCView.Row.ItemArray["MenuCaption"].ToString(), drCView.Row.ItemArray["ChildID"].ToString(), "", drCView.Row.ItemArray["MenuUrl"].ToString());
                  oParentMenuItem.Items.Add(oChildMenuItem);
                }
            }
        }


注意:请根据您的要求更改代码.通常,我会在此文本框中输入编码,因此,如果您有任何疑问/问题,请告诉我.


NOTE : Please change code based on your requirement. Mostly I typed coding in this textbox, so let me know if you have any doubt/issue.


这篇关于动态菜单创建.... asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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