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;
}
查看全文
相关阅读:
[Groovy] List里的Inject方法
[Groovy]你意想不到的用法
buildr学习笔记(1): buildr的安装
[Groovy]如何在Groovy里得到命令行的返回值
underscore.js
[Groovy] *符号在Groovy里的一种特殊用法
[Groovy]如何定义和使用一个Java里的Enum类型
[Ruby]$: 是什么意思?
Optional Parameter/Default Values
如何在Rake 的Task里加入多个输入参数
原文地址:https://www.cnblogs.com/Magicam/p/1215616.html
最新文章
ViewState使用兼谈序列化
SQL批量循环插入数据
ViewState与Session
超级无敌正则表达式(匹配日期时间)
DropdownList小技巧
ASP.NET Cookie 概述
ASP.NET Cookie使用(转)
IEnumerable
IEnumerator
Asp.net動態添加控件(转)
C#中的DBNull、Null、""和String.Empty解释【转】
热门文章
write2flash与rom convert_hex2ver下载
串行通讯简单认识 单工、半双工和全双工的定义
关于TI DSP的EDMA乒乓操作
在FPGA设计环境中加时序约束
关于tsk和mbx
EDMA 和QDMA
C64X DSP EDMA小结及实例详解(ZZ)
C64X DSP EDMA小结及实例详解(ZZ)
DFF和latch
关于关键字 volatile
Copyright © 2011-2022 走看看