創建表及插入模擬數據
CREATE TABLE [dbo]
[NoteId] [decimal](
[ParentId] [decimal](
[sText] [nvarchar](
[sValue] [nvarchar](
[sURL] [nvarchar](
[sTarget] [nvarchar](
[Chger] [nvarchar](
[ChgTime] [nvarchar](
CONSTRAINT [PK_sysMenuTree] PRIMARY KEY CLUSTERED
(
[NoteId] ASC
)WITH (PAD_INDEX = OFF
) ON [PRIMARY]
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
insert into sysMenuTree values(
在ASP
<%@ Page Language=
<!DOCTYPE html PUBLIC
<html xmlns=
<head runat=
<title></title>
</head>
<body>
<form id=
<div>
<asp:TreeView ID=
</asp:TreeView>
</div>
</form>
</body>
</html>
using System;
using System
using System
using System
public partial class _Default : System
{
private readonly string ConnString = @
private DataTable dt = null;
protected void Page_Load(object sender
{
if(!IsPostBack)
{
dt = new DataTable();
GetMenuToDataTable(
BindTree(dt
}
}
private void BindTree(DataTable dtSource
{
DataRow[] rows = dtSource
foreach(DataRow row in rows)
{
TreeNode node = new TreeNode();
node
node
BindTree(dtSource
if(parentNode == null)
{
treeMenu
}
else
{
parentNode
}
}
}
private DataTable GetMenuToDataTable(string query
{
using(SqlConnection conn = new SqlConnection(ConnString))
{
SqlCommand cmd = new SqlCommand(query
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada
}
return dt;
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12278.html