ASP. net js + SQL unlimited tree menu

Source: Internet
Author: User
The implementation of the function is also based on the js api written by others. I can click the JS tree menu here To uncompress the downloaded file. api.html is a description of the API.
Development tools: Visual Studio 2008 team system
Database: SQL Server 2005 Development Edition
Jquery: 1.3
Nhib.pdf is used for data access: getting started. You can use the object in ADO. Net to access the database and read the result set in your own test.

I. Browsing Effect

Ii. Database Table Design
Column name Data Type
Id int
Parentmenuid int
Menuname nvarchar (50)
Menucode nvarchar (20)
Menutaxis int
Menuclickurl nvarchar (200)
III, Code Implementation
Front-end: <% @ 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 > No title page </ 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. js" > </ Script >
< Script Type = "Text/JavaScript" SRC = "JS/jquery. dimensions. js" > </ Script >
< Script Type = "Text/JavaScript" SRC = "JS/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 >

Background:
Before executing the page_load method, I output an IMG control to the page to display a GIF animation when loading data slowly, prompting that the data is being loaded. UsingSystem;
UsingSystem. text;
UsingSunzonmodel;
UsingSunzondal;
UsingSystem. 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)
{
// Spell 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, 'System module '); " );

Createtree (0);

appendtree. append ( " document. write (d); " )
. append ( " D. closeall (); " )
. append ( " " );

Ltltree. Text=Appendtree. tostring ();

// Clientscript. registerstartupscript (this. GetType (), "key", appendtree. tostring ());
}
}
///   <Summary>
/// Recursively add Tree nodes
///   </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 );
// Displays a message indicating that data is being loaded.
Response. Write ( " " Images / Loading / Loading01.gif \ " Id = \ " Imgloading \ " Alt = \ " Loading data \ " /> " );
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.