来自数据库的JQuery菜单 [英] JQuery Menu From Database

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

问题描述

你好,我如何在两个类别和一个前面的chides上循环拖曳表?

类别包含(主页,关于,联系我们等...)

childes将包含属于这些类别的页面,如何制作一个循环进入两个表的递归方法并使用字符串生成器构建菜单?



我的代码就在这里停止

hello , how can i loop on tow tables one for categories and one fore chides ?
the category contain (" Home , About , Contact Us , etc...)
the childes will contain the pages that belongs to that categories , how to make a recursive method that loop into the tow tables and make build the menu with string builder ?

my code is stopped right here

protected void Page_Load(object sender, EventArgs e)
 {
     MenuSelect();
 }

 void MenuSelect()
 {
     StringBuilder menuItem = new StringBuilder();
     SqlConnection con;
     SqlDataReader dr = DataManager.GetDataReader("Select_Menu",out con);
     if (dr.HasRows)
     {
         while (dr.Read())
         {

             menuItem.Append("<ul id=\"nav\" class=\"sf-menu\">");

             //i how can i loop ?
             menuItem.AppendFormat("<li><a href=\"/About/{0}\">{1}<span class=\"subheader\">{2}</span></a>", dr[3], dr[1], dr[2]);


         }
     }

     con.Close();
     menuControl.Text = menuItem.ToString();
 }

推荐答案

我不知道你的数据结构是如何设置的,但是如果DataManager.GetDataReader可以可以为菜单的每个级别调用此功能。我确定情况并非如此,但凭借这种假设,这就是你如何进行递归。如果你想要一个更具体的解决方案,那么请解释你的数据结构,你如何访问它以及它返回的格式



I have no idea how your data structure is set up but if DataManager.GetDataReader can be called for each level of the menu this this would work. I''m sure that''s not the case but with that assumption this is how you could do recursion. If you want a solution that is more specific then explain how your data is structured, how you access it and what format it is returned in

protected void Page_Load(object sender, EventArgs e)
 {
     //Do you need the About at this stage?  otherwise use ""
     MenuSelect("Select_Menu","About/");
 }

 void MenuSelect(string menuParent, string curentNav)
 {

     StringBuilder menuItem = new StringBuilder();

     SqlConnection con;
     SqlDataReader dr = DataManager.GetDataReader(menuParent,out con);
     if (dr.HasRows)
     {
         while (dr.Read())
         {
             //Each menu subset will have this ul
             menuItem.Append("<ul id="\"nav\"" class="\"sf-menu\"">");

             //write the current nav or add test if no link
             menuItem.AppendFormat("<li><a href="\"/"+curentNav+"{0}\"">{1}<span class="\"subheader\"">{2}</span></a>", dr[3], dr[1], dr[2]);

            // recurse for the next menu item
            menuItem.Append(MenuSelect(dr[1], curentNav + "/" + dr[3]));

            //close up tags
            menuItem.Append(</li>);

            menuItem.Append("</ul>");

         }
     }

     con.Close();
     menuControl.Text = menuItem.ToString();
 }


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

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