asp.net中的动态菜单问题

时间:2015-11-18 16:18:42

标签: javascript c# css asp.net .net-4.0

我已经创建了一个动态菜单作为用户控件,它在测试应用程序中工作正常。但是当我集成到实时应用程序时,子菜单项只有在我单击父菜单项时才会出现,而不是将鼠标悬停在菜单上子项目,即当我使用浏览器开发人员工具控制台窗口时页面加载或回发子项目未到来时,每当页面加载或回发时都会出现错误,如下所示

SCRIPT1004: Expected ';' 
Default.aspx, line 728 character 24 

页面可以改变,所以这里是Default.aspx

我用于动态菜单的代码是

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = this.GetData(0);
            PopulateMenu(dt, 0, null);
        }
    }
    private void PopulateMenu(DataTable dt, int parentMenuId, MenuItem parentMenuItem)
    {
        string currentPage = Path.GetFileName(Request.Url.AbsolutePath);
        foreach (DataRow row in dt.Rows)
        {
            MenuItem menuItem = new MenuItem
            {
                Value = row["MENUID"].ToString(),
                Text = row["MENUNAME"].ToString(),
                NavigateUrl = row["URL"].ToString(),
                Selected = row["URL"].ToString().EndsWith(currentPage, StringComparison.CurrentCultureIgnoreCase)
            };
            if (parentMenuId == 0)
            {
                dynamicMenu.Items.Add(menuItem);
                DataTable dtChild = this.GetData(int.Parse(menuItem.Value));
                PopulateMenu(dtChild, int.Parse(menuItem.Value), menuItem);
            }
            else
            {
                parentMenuItem.ChildItems.Add(menuItem);
                //dynamicMenu.Items.Add(menuItem);
                DataTable dtChild = this.GetData(int.Parse(menuItem.Value));
                PopulateMenu(dtChild, int.Parse(menuItem.Value), menuItem);
            }
        }
    }


    private DataTable GetData(int parentMenuId)
    {
        string query = "SELECT MENUID, MENUNAME, ACTIVE, URL,APPLICATION_ID FROM MENUS_APPS WHERE PARENTID = :ParentMenuId AND APPLICATION_ID ='" + Global.GetApplicationId() + "' and ACTIVE='Y' and ROLE_ID = 1";
        string constr = ConfigurationManager.ConnectionStrings["UserConnections"].ConnectionString;
        using (OracleConnection con = new OracleConnection(constr))
        {
            DataTable dt = new DataTable();
            using (OracleCommand cmd = new OracleCommand(query))
            {
                using (OracleDataAdapter sda = new OracleDataAdapter())
                {
                    cmd.Parameters.AddWithValue(":ParentMenuId", parentMenuId);
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    sda.Fill(dt);
                }
            }
            return dt;
        }
    }

我知道为什么会这样吗??

要检查web.config中的任何内容

0 个答案:

没有答案