zoukankan
html css js c++ java
DropDownList分层显示!
public
static
void
BindDropFatherItem( DropDownList DropDownList )
{
DropDownList.Items.Clear();
string
strSql
=
"
select * from Department
"
;
DataTable dt
=
DB.GetTable( strSql );
//
获取所有节点
//
判断跟节点数量
string
strSql1
=
"
select count(*) from Department where ParentID = 0
"
;
int
ParentCount
=
Convert.ToInt32( DB.ExecuteScalar( strSql1 ) );
if
( dt.Rows.Count
>
0
)
{
foreach
( DataRow dr
in
dt.Rows )
{
if
( ParentCount
==
0
)
{
if
( dr[
"
ParentID
"
].ToString().Trim()
==
"
0
"
)
//
绑定根节点
{
DropDownList.Items.Insert(
0
,
"
请选择
"
);
DropDownList.Items.Add(
new
ListItem( dr[
"
DepName
"
].ToString(), dr[
"
DepID
"
].ToString() ) );
BindDropChildItem( DropDownList, dt, dr[
"
DepID
"
].ToString(),
1
);
}
}
else
{
if
( dr[
"
ParentID
"
].ToString().Trim()
==
"
0
"
)
//
绑定根节点
{
DropDownList.Items.Add(
new
ListItem( dr[
"
DepName
"
].ToString(), dr[
"
DepID
"
].ToString() ) );
BindDropChildItem( DropDownList, dt, dr[
"
DepID
"
].ToString(),
1
);
}
}
}
}
}
public
static
void
BindDropChildItem( DropDownList DropDownList, DataTable dt,
string
id,
int
length )
{
DataRow[] rows
=
dt.Select(
"
ParentID='
"
+
id
+
"
'
"
,
"
DepID ASC
"
);
//
取出id子节点进行绑定
for
(
int
i
=
0
; i
<
rows.Length; i
++
)
{
DropDownList.Items.Add(
new
ListItem( Department.SpaceLength( length )
+
rows[ i ][
"
DepName
"
].ToString(), rows[ i ][
"
DepID
"
].ToString() ) );
BindDropChildItem( DropDownList, dt, rows[ i ][
"
DepID
"
].ToString(), length
+
1
);
//
空白数目加1
}
}
//
子节点前面的空白数
public
static
string
SpaceLength(
int
i )
{
string
space
=
""
;
for
(
int
j
=
0
; j
<
i; j
++
)
{
space
+=
"
------
"
;
//
分层显示字符;
}
return
space;
}
查看全文
相关阅读:
emberjs初学记要
自我的一点介绍(七夕礼物)
JavaScript数据类型
Vue+Webpack项目配置
Git知识点整合
Log4j简单配置解析
如何明智地向程序员提问
Navicat连接mysql报错1251
多表查询sql语句
PLSQL面向对象
原文地址:https://www.cnblogs.com/Magicam/p/1215616.html
最新文章
模拟websocket推送消息服务mock工具二
使用electron开发一个h5的客户端应用创建http服务模拟后台接口mock
electron快速开始
带你使用h5开发移动端小游戏
react实例之todo,做一个实时响应的列表操作
reactjs学习一(环境搭配react+es6+webpack热部署)
react native 学习一(环境搭配和常见错误的解决)
[js开源组件开发]html5标签audio的样式更改
[js开源组件开发]localStorage-cache本地存储的缓存管理
emberjs学习二(ember-data和localstorage_adapter)
热门文章
使用ruby搭建简易的http服务和sass环境
emberjs学习一(环境和第一个例子)
【2015上半年总结】js开源组件开发系列索引
Jest 前端单元测试工具
又到圣诞节,让你的网页下起雪(js特效)
js组件开发-移动端地区选择控件mobile-select-area
详解nodejs中使用socket的私聊和公聊的办法
[js开源组件开发]localStorage-cache本地存储的缓存管理
emberjs学习二(ember-data和localstorage_adapter)
使用ruby搭建简易的http服务和sass环境
Copyright © 2011-2022 走看看