菜单列表与数据库 [英] Menu Listing With Database

查看:113
本文介绍了菜单列表与数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// con.Open();
        SqlDataAdapter dadCategories = new SqlDataAdapter("SELECT ID,Name FROM Category order by Name", con);
        SqlDataAdapter dadSubCat = new SqlDataAdapter("SELECT BD,ID,BName FROM Brand order by BName", con);

        // Add the DataTables to the DataSet
        DataSet dsCat = new DataSet();
        using (con)
        {
            con.Open();
            dadCategories.Fill(dsCat, "Category");
            dadSubCat.Fill(dsCat, "Brand");
        }

        // Add a DataRelation
        dsCat.Relations.Add("Children", dsCat.Tables["Category"].Columns["ID"], dsCat.Tables["Brand"].Columns["ID"]);
        // Add the Category nodes
        int count = 0;

        foreach (DataRow categoryRow in dsCat.Tables["Category"].Rows)
        {

            MenuItem mNode = new MenuItem(Convert.ToString(categoryRow["Name"]), "", "", "~/item.aspx?CatID=" + Convert.ToString(categoryRow["ID"]), "_parent");
            Menu1.Items.Add(mNode);

            // Get matching Sub Category
            DataRow[] subCatRows = categoryRow.GetChildRows("Children");
            foreach (DataRow row in subCatRows)
            {
                string subCatName = Convert.ToString(row["BName"]);
                MenuItem subCatItems = new MenuItem(subCatName, "", "", "~/item.aspx?CatID=" + Convert.ToString(row["ID"]) + "&BID=" + Convert.ToString(row["BD"]), "_parent");
                Menu1.Items(count).ChildItems.Add(subCatItems);
               
               
                
                
            }
            count = count + 1;
        }
    }









< big> ERROR :

非可调用成员''System.Web.UI.WebControls.Menu.Items''不能像方法一样使用

< br $> b $ b



请帮帮我





ERROR:
Non-invocable member ''System.Web.UI.WebControls.Menu.Items'' cannot be used like a method



please help me

推荐答案

这是C#。你用[] not()索引项目。



项目[count]



那是'猜测,如果你告诉我们哪一行有错误会有所帮助。
This is C#. you index items with [] not ().

Items[count]

That''s a guess, it would help if you told us what line has the error.


语法错误:
Menu1.Items(count).ChildItems.Add(subCatItems); // You can't put int value as a parameter of Items

< br $> b $ b

请参阅 MSDN [ ^ ]



所以它可能是这样的,



see MSDN[^]

so it could be like this,

Menu1.Items(count.ToString()).ChildItems.Add(subCatItems);


这篇关于菜单列表与数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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