如何将url分配给运行时生成的主菜单... [英] How to Assign the url to main menu generate at run time...

查看:71
本文介绍了如何将url分配给运行时生成的主菜单...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在运行时生成的菜单项.
有主菜单和他们的chailds,chailds有其导航URL,但我必须将URL分配给主页的主菜单...


为此,我已经完成了此编码


I have a menu item which is generated at run time.
there are main menu & their chailds,chailds has its navigate url but i have to assign url to main menu for home page...


for this i have done this codding


connection(); 
            SqlCommand cmd = new SqlCommand("menus", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@code", Session["username"].ToString());
            SqlDataAdapter adap = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adap.Fill(ds);
            MainMenu.Items.Clear();
            ds.Relations.Add("Children", ds.Tables[0].Columns["menu_name"], ds.Tables[1].Columns["menu_name"],false);
            foreach (DataRow masterRow in ds.Tables[0].Rows)
            {
                MenuItem masterItem = new MenuItem(" " + (string)masterRow["menu_name"] + " ");
                MainMenu.Items.Add(masterItem);
                foreach (DataRow childRow in masterRow.GetChildRows("Children"))
                {

                    MenuItem childItem = new MenuItem((string)childRow["menuitem_name"]);
                    masterItem.ChildItems.Add(childItem);
                    childItem.NavigateUrl = ((string)childRow["menu_url"]);
                }
            }



现在如何将URL关联到主菜单..
请帮助..



Now How can i assine the url to main menu..
plz help..

推荐答案

您尝试过此方法吗?
Did you try this?
foreach (DataRow masterRow in ds.Tables[0].Rows)
{
    MenuItem masterItem = new MenuItem(" " + (string)masterRow["menu_name"] + " ");
    masterItem.NavigateUrl = ((string)masterRow["menu_url"]);//This line
    MainMenu.Items.Add(masterItem);
    foreach (DataRow childRow in masterRow.GetChildRows("Children"))
    {

        MenuItem childItem = new MenuItem((string)childRow["menuitem_name"]);
        masterItem.ChildItems.Add(childItem);
        childItem.NavigateUrl = ((string)childRow["menu_url"]);
    }
}


这篇关于如何将url分配给运行时生成的主菜单...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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