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
}
查看全文
相关阅读:
AIoT 2020 年分析
TensorFlow解析常量、变量和占位符
TensorFlow编程结构
对端边缘云网络计算模式:透明计算、移动边缘计算、雾计算和Cloudlet
Harmony生命周期
立体显示与BCN双稳态手性向列相
显示技术示例
SystemML大规模机器学习,优化算子融合方案的研究
改天有空看看 1
gradle 123123
原文地址:https://www.cnblogs.com/wfcfan/p/1233450.html
最新文章
SAP CRM附件模型的Authorization scope原理介绍
如何用代码动态生成ABAP类型
动态隐藏某些特殊类型的SAP CRM附件
引起SAP WebClient UI页面出现超时(time out)错误的另一个原因
SAP WebClient UI component模型元数据解析工具
如何把一个ABAP视图添加到SAP GUI的收藏夹里
SAP CRM产品主数据ID的生成逻辑介绍
SAP CRM note创建按钮被禁用的原因分析
做好数据库运维,资源管理技术必须要掌握
技术实践丨Prometheus+Grafana搭建HBase监控仪表盘
热门文章
跟随报文,开启一段奇妙之旅
LiteOS:剖析时间管理模块源代码
跟我学ModelArts丨探索ModelArts平台个性化联邦学习API
一个合格的CloudNative应用:程序当开源软件编写,应用配置外置
华为云应用服务网格最佳实践之从Spring Cloud 到 Istio
华为云数据库GaussDB(for openGauss):初次见面,认识一下
化蛹成蝶,华为云DevCloud助力互联网+转型,重构钢铁产业链
数仓集群管理:单节点故障RTO机制分析
智能物联网(AIoT,2020年)(中)
智能物联网(AIoT,2020年)(上)
Copyright © 2011-2022 走看看