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;
}
查看全文
相关阅读:
Problem E. Matrix from Arrays(杭电2018年多校第四场+思维+打表找循环节)
Reachability from the Capital(Codeforces Round #490 (Div. 3)+tarjan有向图缩点)
Network of Schools(POJ1326+有向图进行缩点)
John's trip(POJ1041+欧拉回路+打印路径)
Watchcow(POJ2230+双向欧拉回路+打印路径)
Network(POJ3694+边双连通分量+LCA)
Problem L. Visual Cube(杭电多校2018年第三场+模拟)
floyd骚操作——传递闭包
Remmarguts' Date(POJ2449+最短路+A*算法)
Transformation(线段树+HDU4578+多种操作+鬼畜的代码)
原文地址:https://www.cnblogs.com/Magicam/p/1215616.html
最新文章
iptables防DDOS攻击和CC攻击配置
nginx502问题
http 错误代码表
简单配置nginx使之支持pathinfo
Linux下添加php的zip模块
php5模块pdo、pdo_mysql、mysqli的添加
C#高级编程笔记 (1至6章节)数组,类/方法/泛型
Autoit 3 常用的语句
Autoit脚本调用pscp上传小程序
windows2008R2-Exchange管理笔记
热门文章
NightMare2(SCU4527+dijkstra+二分)
随机生成数组函数+nth-element函数
Bazinga(HDU5510+KMP)
洛谷 P3375 【模板】KMP字符串匹配
Optimal Milking(POJ2112+二分+Dinic)
Drainage Ditches(POJ1273+网络流+Dinic+EK)
Desert King(POJ2728+最优比率生成树+二分)
Frogs' Neighborhood(POJ1659+Havel-Hakimi定理)
Katu Puzzle(POJ3678+2-SAT问题+tarjan缩点)
Problem B. Harvest of Apples(杭电2018年多校+组合数+逆元+莫队)
Copyright © 2011-2022 走看看