注册 登录
编程论坛 JavaScript论坛

导航下拉菜单的问题

myhorsefsy 发布于 2010-04-20 13:23, 549 次点击
我在尝试自己做一个导航下拉菜单.我的思路是这样的.从数据库获取菜单信息然后用js在页面画出来.但是就不成功.请高手指点迷津呀.或者给个能正常使用的版本.
2 回复
#2
foktime2010-04-21 17:04
看看你代码怎么写的 贴上来
#3
myhorsefsy2010-04-22 16:18
版主,你给个例子吧.
我的后台代码是这样的.
str+=这部分是有问题的.我还没想好该怎么写比较.,用贴的方式不知道该怎么循环了.
public string getMenu()
        {
            string str = null;
            int i = 0;
            SqlConnection sqlcon = new SqlConnection(connectionString);
            sqlcon.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select ID,parentID,text from topmenu where parentID=0  order by IsBoot", sqlcon);
            DataSet ds = new DataSet();
            sda.Fill(ds);

            for (i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                //MenuItem menunode = new MenuItem();
                //menunode.Text = dr["text"].ToString();
                //menunode.Value = dr["ID"].ToString();
                //Menu1.Items.Add(menunode);
                //getMenuchild(menunode, menunode.Value, Convert.ToInt32(dr["ID"]));

                str += "{text:'" + ds.Tables[0].Rows[i]["text"].ToString() + "','topid':'" + i + "','colid':'" + i + "','value':'" + ds.Tables[0].Rows[i]["text"].ToString() + "','fun':function(){}},";
                str += getMenuchild("mpmenu" + i, Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()),i);
                //str += " ";
                //i++;
            }

            return str;
        }
        //public string getMenuchild(MenuItem node,string value ,int id)
        public string getMenuchild(string strmenu, int id,int j)
        {
            string childstr = null;
            int i = 0;
            SqlConnection sqlcon = new SqlConnection(connectionString);
            sqlcon.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select ID,parentID,text from topmenu where parentID='" + id + "'  order by IsBoot", sqlcon);
            DataSet ds = new DataSet();
            sda.Fill(ds);

            for (i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                //MenuItem menunode = new MenuItem();
                //menunode.Text = dr["text"].ToString();
                //menunode.Value = dr["ID"].ToString();
                //node.ChildItems.Add(menunode);

                childstr += "{text:'" + ds.Tables[0].Rows[i]["text"].ToString() + "','topid':'0','colid':'1','value':'" + ds.Tables[0].Rows[i]["text"].ToString() + "','fun':function(){}},";
                //childstr += strmenu + ".mMenuAddItem(mpmenuchild" + i + ");";
                childstr += getMenuchild("mpmenuchild" + i, Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()),i);
            }

            return childstr;
        }
1