如何从数据库表数据生成无序列表?

时间:2011-03-19 08:45:16

标签: jquery asp.net sql-server

嗨我有一个无序列表<ul><li><ul><li>

我创建了一个表来填充无序列表,但是如何将这些数据提取到liul 该表由家庭,组织(以子项为策略,员工详细信息)等组成。如何填充这些ulli以及li的子项来自sqlserver2005表的数据? 我不应该使用任何asp.net内置控件,如asp.net menu

foreach (DataRow row in dt.Rows) 
        {      
            int currentDepth =  Convert.ToInt32(row["Depth"]);      
            if (lastDepth < currentDepth) 
            {
                output.Append("<ul class=\"dropdown\">");         
                numUL++ ;    
            }     
            else if (lastDepth > currentDepth) 
            {         
                output.Append("</li></ul></li>");         
                numUL--   ;  
            }     
            else if (lastDepth > -1) 
            {
                output.Append("</li>");     
            }      
            output.AppendFormat("<li class=\"depth-{1}\">{0}", row["ApplicationName"], currentDepth);      
            lastDepth = currentDepth; 
        }  
        for (int i = 1;i <= numUL;i++) 
        {     
            output.Append("</li></ul>"); 
        }    
        Literal1.Text = output.ToString(); 

我根据上面的代码制作了导航栏 我的导航栏看起来像这样

  

首页|组织机构|人才招聘|帮助问题

我正确地得到了所有的li(就像组织下的部门和用户一样) 我有一个问题,我如何动态地获取上面的代码

我的表看起来像这样

ApplicationID    ApplicationName  ParentKey  Depth  URL  
1                 HOME             NULL      0      #   
2                 Organisation     NULL      0      #
3                 Department       2         1      #
4                 User             2         1      #  
5                 Issues           NULL      0      # 
6                 issuestrack      5         1      #
7                 Help             NULL      0      #
8                 helpneeded       7         1      #
提前

thanx

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:-1)

尝试查看select的“for xml”子句。既然我同意这看起来像家庭作业,你将不得不自己做一些挖掘。祝你好运!