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
}
查看全文
相关阅读:
getWritableDatabase()与getReadableDatabase()方法
使用drawBitmapMesh扭曲图像
移动游戏背景
使用Matrix控制图片和组件的变化
使用Matrix控制图像或组件变换的步骤
1105: 零起点学算法12——求2个日期之间的天数
1104: 零起点学算法11——求梯形面积
1103: 零起点学算法10——求圆柱体的表面积
1102: 零起点学算法09——继续练习简单的输入和计算(a-b)
1101: 零起点学算法08——简单的输入和计算(a+b)
原文地址:https://www.cnblogs.com/wfcfan/p/1233450.html
最新文章
Android应用开发基础篇(9)-----SharedPreferences
Android应用开发基础篇(8)-----SurfaceView
Android应用开发提高篇(2)-----文本朗读TTS(TextToSpeech)
Android应用开发基础篇(7)-----BroadcastReceiver
Android应用开发提高篇(1)-----获取本地IP
Android应用开发基础篇(6)-----Service
Android应用开发基础篇(5)-----Handler与多线程
Android应用开发基础篇(4)-----TabHost(选项卡)
2、文件
HTTP报文结构
热门文章
HTTP网络协议栈
HTTP语法
HTTP状态码
IP分组
URL和URI区别
使用ContentProContentProvider共享生词本数据
使用ContentProvider管理多媒体-----向多媒体数据中添加数据
使用ContentProvider管理多媒体-----查看多媒体数据中的所有图片
使用ContentProvider管理联系人------添加联系人
使用ContentProvider管理联系人------搜索联系人
Copyright © 2011-2022 走看看