开发者

How to generate an unordered list from database table data?

hi i have an unordered list <ul><li><ul><li>

I had made a table to fill the unordered list but how to fetch that data into li and ul the table consists of home, organisation (with children as policy, employeesdetails), and so on.. How do i fill these ul and li's and children of li's with data from sqlserver2005 table? I'm not supposed to use any asp.net built in controls like 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(); 

i have made the navigation bar based on above code my navbar looks like this

Home|Organisation|Recruitment|Help|Issues

i am getting all the li's properly(like department and users under organisation) i have one prolem how do i get the urls dynamically to the above code

my table looks like this

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 in advance


Building a Database Driven Hierarchical Menu using ASP.NET and SooperFish Jquery Plugin


Try looking at the "for xml" clause for your select. Since I agree that this looks like homework, you're going to have to do some digging yourself. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜