zoukankan
html css js c++ java
asp.net中treeview的使用
protected
void
treeviewProductDataBind()
{
SqlConnection cn
=
new
SqlConnection(
"
server=192.168.1.227;database=Northwind;user id=sa;password=;
"
);
SqlDataAdapter daCategories
=
new
SqlDataAdapter(
"
select CategoryID,CategoryName from Categories
"
, cn);
DataSet dsCategories
=
new
DataSet();
daCategories.Fill(dsCategories);
SqlDataAdapter daProducts
=
new
SqlDataAdapter(
"
select ProductID,ProductName,CategoryID from Products
"
, cn);
DataSet dsProducts
=
new
DataSet();
daProducts.Fill(dsProducts);
int
CategoriesCount
=
dsCategories .Tables [
0
].Rows .Count ;
int
ProductsCount
=
dsProducts.Tables[
0
].Rows.Count;
for
(
int
i
=
0
;i
<
CategoriesCount;i
++
)
{
TreeNode treenodeParent
=
new
TreeNode();
treenodeParent.Text
=
dsCategories.Tables[
0
].Rows[i][
"
CategoryName
"
].ToString();
treenodeParent.Value
=
dsCategories.Tables[
0
].Rows[i][
"
CategoryID
"
].ToString();
treenodeParent.ImageUrl
=
"
folder.gif
"
;
//
treenodeParent.NavigateUrl = "";
//
treenodeParent.Target = "";
this
.treeviewProduct.Nodes.Add(treenodeParent);
for
(
int
j
=
0
; j
<
ProductsCount; j
++
)
{
if
(dsCategories.Tables[
0
].Rows[i][
"
CategoryID
"
].ToString()
==
dsProducts.Tables[
0
].Rows[j][
"
CategoryID
"
].ToString())
{
TreeNode treenodeChild
=
new
TreeNode();
treenodeChild.Text
=
dsProducts.Tables[
0
].Rows[j][
"
ProductName
"
].ToString();
treenodeChild.Value
=
dsProducts.Tables[
0
].Rows[j][
"
ProductID
"
].ToString();
treenodeChild.ImageUrl
=
"
word.gif
"
;
//
treenodeChild.NavigateUrl = "";
//
treenodeChild.Target = "";
treenodeParent.ChildNodes.Add(treenodeChild);
}
}
}
}
protected
void
treeviewProduct_TreeNodeExpanded(
object
sender, TreeNodeEventArgs e)
{
foreach
(TreeNode treenode
in
this
.treeviewProduct.Nodes)
{
if
(treenode.Value
!=
e.Node.Value)
{
treenode.CollapseAll();
}
else
{
treenode.ImageUrl
=
"
folderopen.gif
"
;
}
}
}
//
前台页面
<
asp:TreeView ID
=
"
treeviewProduct
"
runat
=
"
server
"
ShowLines
=
"
true
"
Font
-
Size
=
"
12px
"
ExpandDepth
=
"
0
"
OnTreeNodeExpanded
=
"
treeviewProduct_TreeNodeExpanded
"
CollapseImageUrl
=
"
folder.gif
"
ExpandImageUrl
=
"
folderopen.gif
"
>
</
asp:TreeView
>
查看全文
相关阅读:
Catch That Cow(poj 3278)
补丁vs错误(codevs 2218 错误答案)
泥泞的道路(codevs 1183)
一塔湖图(codevs 1024)
多源最短路(codevs 1077)
html5.js让IE(包含IE6)支持HTML5元素方法
字符数组的定义与使用具体解析
QT解析嵌套JSON表达式
SVN入门-2分钟教你入门
Codeforces Round#251(Div 2)D Devu and his Brother
原文地址:https://www.cnblogs.com/wucf2004/p/792968.html
最新文章
【C语言学习】《C Primer Plus》第13章 文件输入/输出
JedisPool异常Jedis链接处理
【C语言学习】《C Primer Plus》第12章 存储类、链接和内存管理
贡献一下多年珍藏的特效例子
前端系列——React开发必不可少的eslint配置
利用angular4和nodejs-express构建一个简单的网站(一)——构建前后端开发环境
使用Webpack+Gulp开发运行于Dcloud平台HTML5+引擎的混合APP项目经验分享
dva+react+antd+webpack 项目开发配置
记一个ios滚动穿透问题
基于 HTML5 Canvas 绘制的电信网络拓扑图
热门文章
现代CSS进化史
vue打包后空白页问题全记录 (background路径,css js404,jsonp等);
vue全家桶+axios+jsonp+es6 仿肤君试用小程序
js制作带有遮罩弹出层实现登录小窗口
css伪元素before/after和画三角形的搭配应用
村村通(codevs 2627)
电话连线(codevs 1003)
奇怪的梦境(codevs 2833)
昂贵的聘礼(poj 1062)
传纸条(洛谷 1006)
Copyright © 2011-2022 走看看