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;
}
查看全文
相关阅读:
Asp.Net WebService 使用后来管理系统对接口方法进行公开控制
ASP.NET使用NPOI加载Excel模板并导出下载
VS2010 根据模型生成数据库 打开edmx.sql文件时 vs出现无响应的解决方案
ASP.NET中Session简单原理图
三层架构学习总结图
备忘录
帶編號漏洞列表
pwn with glibc heap(堆利用手册)
基于qemu和unicorn的Fuzz技术分析
winafl 源码分析
原文地址:https://www.cnblogs.com/Magicam/p/1215616.html
最新文章
zList一个块状链表算法可以申请和释放同种对象指针,对于大数据量比直接new少需要差不多一半内存
四、Snapman多人协作电子表格之——Exprtk脚本
三、Snapman多人协作电子表格之——软件的基本功能
二、Snapman多人协作电子表格之——软件下载安装与配置
一、Snapman多人协作电子表格之——Snapman自我介绍
Snapde电子表格编写Exprtk脚本进行数据运算
流域水环境风险管理决策支持平台研发随笔(2)
流域水环境风险管理决策支持平台研发随笔(1)
科斯定理与区块链
Proj.Net 投影介绍
热门文章
微信公众号开发笔记
DokuWiki的发现之旅
应用程序启动管理 Winform版
外地驾照迁入北京流程
人生一小时
C#中Timer使用及解决重入问题
C#通用类Helper整理
ASP.NET MVC中使用Dropzone.js实现图片的批量拖拽上传
SQL Pretty Printer-不错的SQL格式化工具
百度云推送-服务端 C# SDK
Copyright © 2011-2022 走看看