ASP.NET JS+Sql无限级树型菜单

 

二、数据库表设计
列名      数据类型
ID          int   
ParentMenuID    int   
MenuName      nvarchar(50)   
MenuCode          nvarchar(20)   
MenuTaxis           int   
MenuClickURL    nvarchar(200)   
三、代码实现
前台:
 

<% @ Page Language = " C# "  AutoEventWireup = " true "  CodeFile = " Default.aspx.cs "  Inherits = " _Default "   %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head  runat ="server" >
    
< title > 无标题页 </ title >
    
<!--  Tree CSS  -->
    
< link  rel ="StyleSheet"  href ="Style/dtree.css"  type ="text/css"   />
    
<!--  Tree JS -->
    
< script  type ="text/javascript"  src ="JS/dtree.js" ></ script >
    
<!-- JQuery LIB  -->
    
< script  type ="text/javascript"  src ="JS/JQuery/jquery.js" ></ script >
    
< script  type ="text/javascript"  src ="JS/JQuery/jquery.dimensions.js" ></ script >
    
< script  type ="text/javascript"  src ="JS/JQuery/jquery.corner-min.js" ></ script >
    
< script  type ="text/javascript" >
        $(document).ready(
function () {
            $(
" #imgLoading " ).hide();
        });
    
</ script >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< asp:Literal  ID ="ltlTree"  runat ="server" ></ asp:Literal >
    
</ form >
</ body >
</ html >


后台:
我在Page_Load方法执行前,向页面输出了一个img控件,用于在数据加载慢的时候,显示一个gif动画图,提示数据正在加载
 

using  System;
using  System.Text;
using  SunZonModel;
using  SunZonDAL;
using  System.Collections.Generic;

public   partial   class  _Default : System.Web.UI.Page 
{
    StringBuilder appendTree 
=   new  StringBuilder();
    DALMenu menuInstance 
=   new  DALMenu();
    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        
if  ( ! IsPostBack)
        {
            
// 拼javascript
            appendTree.Append( " <a href=\ " javascript: d.openAll();\ " >Open</a> | <a href=\ " javascript: d.closeAll();\ " >Close</a><br /> " )
                .Append(
" <script type=\ " text / javascript\ " > " )
                .Append(
" d = new dTree('d'); " )
                .Append(
" d.add(0,-1,'系统模块'); " );

            CreateTree(
0 );

            appendTree.Append(
" document.write(d); " )
                .Append(
" d.closeAll(); " )
                .Append(
" </script> " );

            ltlTree.Text 
=  appendTree.ToString();

            
// ClientScript.RegisterStartupScript(this.GetType(),"key",appendTree.ToString());
        }
    }
    
///   <summary>
    
///  递归添加树节点
    
///   </summary>
    
///   <param name="MenuParentID"></param>
     private   void  CreateTree(Int32 MenuParentID)
    {
        IList
< SunZonTMSMenu >  list  =  menuInstance.GetMenuByParentID(MenuParentID);
        
for  (Int32 i  =   0 ; i  <  list.Count; i ++ )
        {
            appendTree.Append(String.Format(
" d.add({0},{1},'{2}','{3}','{2}','_self'); " ,
                list[i].ID, MenuParentID, list[i].MenuName,list[i].MenuClickURL));
            CreateTree(list[i].ID);
        }
    }
    
protected   override   void  OnPreInit(EventArgs e)
    {
        
base .OnPreInit(e);
        
// 显示正在加载数据的提示
        Response.Write( " <img src=\ " Images / Loading / loading01.gif\ "  id=\ " imgLoading\ "  alt=\ " 数据加载中\ "  /> " );
    }
}

摘自:http://www.lanrentuku.com/js/daohang-519.html

摘自:http://www.cnblogs.com/Ferry/archive/2009/08/12/1544608.html

你可能感兴趣的:(数据库,职场,休闲,无限级树行菜单)