Jquery.treeview combines asp.net and database to generate menu navigation bars _jquery

Source: Internet
Author: User
The following example will use the Jquery.treeview in conjunction with the actual application of the project, of course, using the control tree requires the corresponding JS file now
The following will be my production of the TreeView show to everyone to see what we hope to help! You need to download the control tree's JS files and CSS styles before using

Introduction to the table structure

m_id m_name M_parentid M_url m_sort

Then create a new Web site, add CSS folders and JS folders under the new site to store CSS styles and JS, and then add an image folder to store the images of the TreeView
Then we start to realize our function!
Front Code
Copy Code code as follows:

<%@ 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 ">
<title></title>
<link rel= "stylesheet" href= "Css/screen.css"/>
<link rel= "Stylesheet" href= "Css/jquery.treeview.css"/>
<script src= "Js/jquery-1.4.2.js" type= "Text/javascript" ></script>
<script src= "Js/jquery.treeview.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
$ ("#tree"). TreeView ();
})
</script>

<body>
<div id= "Main" >
<a>main demo</a>
<div id= "Sidetree" >
<ul id= "tree" runat= "Server" >
</ul>
</div>
</div>
</body>


Background code:
Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Data;
Using System.Data.SqlClient;
Using System.Web.UI.HtmlControls;
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
DataSet ds = GetDate ();
CreateMenu (ds, NULL, tree);
}
}
Public DataSet getDate ()
{
DataSet ds = new DataSet ();
string config = system.configuration.configurationmanager.connectionstrings["Liveoffice"]. ToString ();
SqlConnection conn = new SqlConnection (config);
SqlDataAdapter da = new SqlDataAdapter ("select * from Systemmenu ORDER by M_sort", Conn);
Da. Fill (DS);
return DS;
}
private void CreateMenu (DataSet ds, String parentid, HtmlGenericControl UL)
{
datarow[] rows;
if (string. IsNullOrEmpty (ParentID))
rows = ds. Tables[0]. Select ("M_parentid is null");/filter
Else
rows = ds. Tables[0]. Select ("m_parentid= '" + ParentID + "");/filter
foreach (DataRow t in rows)
{
datarow[] Childern = ds. Tables[0]. Select ("M_parentid =" + t["m_id"). ToString ());//To determine whether there are child nodes
HtmlGenericControl Serverli = new HtmlGenericControl ("Li");//Generate Li Tag as parent node
if (Childern. Length!= 0 | | ParentID = = "")//Is the parent node
{
Serverli.innertext = t["M_name"]. ToString ();
HtmlGenericControl Serverul = new HtmlGenericControl ("ul");
SERVERLI.CONTROLS.ADD (Serverul);
Ul. Controls.Add (Serverli);
CreateMenu (ds, t["m_id"). ToString (), Serverul);
}
Else
{
Generate label A
HtmlAnchor Newanchorcontrol = new HtmlAnchor ();
Set the properties of label a
Newanchorcontrol.name = "Newanchorcontrol";
newanchorcontrol.innerhtml = t["M_name"]. ToString ();
Newanchorcontrol.href = t["M_url"]. ToString ();
Newanchorcontrol.target = "_black";//Set the location of the display, change it here.
SERVERLI.CONTROLS.ADD (Newanchorcontrol);
Ul. Controls.Add (Serverli);
CreateMenu (ds, t["m_id"). ToString (), UL);
}
}
}
}

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.