在asp.net中创建动态菜单。所有菜单选项在同一行

时间:2018-09-27 14:53:15

标签: asp.net dynamic menu

我试图在Web窗体中动态创建菜单,但是在填充子项时遇到问题。我所有的菜单项都填充在同一行中。但是,期望将子菜单项填充到“悔改”菜单项下。

这是我的代码。

 DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    Delivery_SettingDAL delivery_SettingDAL = new Delivery_SettingDAL();
    ds = delivery_SettingDAL.get_menu_Items();
    dt = ds.Tables[0];
    foreach(DataRow item in dt.Select("PerentID=" + 0))
    {
        MainMenu.Items.Add(new MenuItem(item["menuname"].ToString(), item["MenuID"].ToString(), "", item["Menulocation"].ToString()));
    }

    foreach (DataRow item in dt.Select("PerentID>" + 0))
    {
        MenuItem men1 = new MenuItem(item["menuname"].ToString(), item["MenuID"].ToString(), "", item["Menulocation"].ToString());

            MainMenu.FindItem(item["perentid"].ToString()).ChildItems.Add(men1);
}

and delivery_SettingDAL.get_menu_Items();

private const string PK_GET_MENU_ITEMS = "SELECT MENUID,MENUNAME,MENULOCATION,PERENTID FROM MENU";
 public DataSet get_menu_Items()
        {
            DataSet ds = new DataSet();
            using (OracleConnection oracleConnection = new OracleConnection())
            {

                try
                {
                    oracleConnection.ConnectionString = ConfigurationManager.ConnectionStrings["DataBase"].ToString();

                    oracleConnection.Open();

                    OracleDataAdapter oracleDataAdapter = new OracleDataAdapter(PK_GET_MENU_ITEMS, oracleConnection);

                    oracleDataAdapter.Fill(ds);
                }
                catch (OracleException ex)
                {
                    IDelivery_Setting delivery_Setting = new Delivery_SettingDAL();
                    delivery_Setting.AddExeption(ex.ToString(), "UsersDAL", "VerifyUserID");
                }
                finally
                {
                    oracleConnection.Close();
                }

            }
            return ds;
        }

0 个答案:

没有答案