Home > Web Front-end > JS Tutorial > body text

Jquery.TreeView combines ASP.Net and database to generate menu navigation bar_jquery

WBOY
Release: 2016-05-16 18:20:42
Original
1078 people have browsed it

The following example will use Jquery.TreeView based on the actual application of the project. Of course, using the control tree requires the corresponding js file
Now I will show you the TreeView I generated. I hope it will be helpful to everyone! Before using it, you need to download the js file and Css style of the control tree

Introduce the table structure

M_ID M_Name M_ParentID M_URL M_Sort
Jquery.TreeView combines ASP.Net and database to generate menu navigation bar_jquery
Then create a new website and create a new one Add a CSS folder and a js folder to the website to store Css styles and JS respectively, and add an image folder to store the TreeView pictures
Then we start to implement our functions!
Front-end code

Copy code The code is as follows:

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










< ;body>




Backend code:
Copy code The code is 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() );//Used to determine whether there are child nodes
HtmlGenericControl serverLi = new HtmlGenericControl("li");//Generate Li tag as the 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
[ "M_Name"].ToString();
NewAnchorControl.HRef = t["M_URL"].ToString();
NewAnchorControl.Target = "_black";//Set the displayed position, change it here
serverLi.Controls.Add(NewAnchorControl);
UL.Controls.Add(serverLi);
createmenu(ds, t["M_ID"].ToString(), UL);
}
}
}
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template