zoukankan
html css js c++ java
TreeView(递归)
很简单,不多说
最终效果:
数据库(Access):
代码:
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
runat
="server"
>
<
title
>
无标题页
</
title
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
style
="text-align:center;"
>
<
div
style
="margin:5px; float:left;"
><
asp:TreeView
runat
="server"
ID
="Tree1"
></
asp:TreeView
></
div
>
<
div
style
="margin-left:12px;"
><
asp:GridView
runat
="server"
ID
="GridView1"
></
asp:GridView
></
div
>
</
div
>
</
form
>
</
body
>
</
html
>
public
partial
class
InfoSort : System.Web.UI.Page
{
DataSet ds
=
null
;
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
BindData();
loadtree();
}
}
private
void
loadtree()
{
Tree1.Nodes.Clear();
ds
=
GetDataSet(
"
SELECT * FROM sort
"
);
InitTree(Tree1.Nodes,
0
);
}
private
void
InitTree(TreeNodeCollection Nds,
int
parentid)
{
DataView dv
=
new
DataView();
TreeNode tmpNd
=
null
;
dv.Table
=
ds.Tables[
0
];
dv.RowFilter
=
String.Format(
"
parentid={0}
"
, parentid);
foreach
(DataRowView drv
in
dv)
{
tmpNd
=
new
TreeNode();
tmpNd.Text
=
(
string
)drv[
"
sortname
"
];
//
节点名称
tmpNd.NavigateUrl
=
String.Format(
"
?id={0}
"
, drv[
"
id
"
]);
//
节点URL
//
tmpNd.ImageUrl = "";
//
节点图片
if
(parentid
==
0
)
tmpNd.Expanded
=
true
;
else
tmpNd.Expanded
=
false
;
Nds.Add(tmpNd);
InitTree(Nds[Nds.Count
-
1
].ChildNodes, (
int
)drv[
"
id
"
]);
}
}
private
void
BindData()
{
GridView1.DataSource
=
GetDataSet(
"
select * from sort
"
);
GridView1.DataBind();
}
Dal
#region
Dal
private
OleDbConnection GetConn
{
get
{
string
path
=
Server.MapPath(
"
App_Data/Database2.mdb
"
);
string
_connStr
=
String.Format(
"
Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}
"
, path);
return
new
OleDbConnection(_connStr);
}
}
private
DataSet GetDataSet(
string
sql)
{
OleDbConnection _conn
=
null
;
OleDbDataAdapter odda
=
null
;
DataSet ds
=
null
;
try
{
ds
=
new
DataSet();
_conn
=
GetConn;
_conn.Open();
odda
=
new
OleDbDataAdapter(sql, GetConn);
odda.Fill(ds);
}
catch
(Exception ex)
{
throw
new
Exception(ex.Message);
}
finally
{
if
(odda
!=
null
)
odda.Dispose();
if
(_conn
!=
null
)
{
_conn.Close();
_conn.Dispose();
}
}
return
ds;
}
#endregion
}
查看全文
相关阅读:
linux配置虚拟主机
mysql允许远程登录
php优化
php socket 函数
1-- prometheus安装、图形化界面
Ansible Roles
Ansible 的 Playbook
Ansible 变量
Ansible 模块
Ansible入门;Ansible ad-hoc; ansible-vault加密工具 ;ansible-console
原文地址:https://www.cnblogs.com/wfcfan/p/1233450.html
最新文章
41、Windows和Linux环境下内存分布情况
40、Linux中异常和中断的区别
39、进程终止的几种方式
38、父进程、子进程、进程组、作业和会话
python学习——反射
python学习——面向对象成员
python学习——面向对象练习2
python学习——面向对象嵌套
python学习——面向对象练习1
python学习——面向对象
热门文章
pyhton学习——包
python学习——模块
python学习——异常处理
pyrhon学习——常用模块联系
php学习路线
闲来总结一下正则
配置网站
关于php laravel5.1框架出现路由找不到的情况
云主机上配置lamp环境 php5.6+apache2.2.15+mysql5.1.73
yum 安装 php5.6 和 mysql5.6
Copyright © 2011-2022 走看看