作者热门文章
- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章asp.net实现DropDownList,TreeView,ListBox的无限极分类目录树由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了asp.net实现DropDownList,TreeView,ListBox的无限极分类目录树。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#region DropDownList无限递归显示层次关系
/// <summary>
/// 创建无限分级下拉列表框
/// </summary>
/// <param name="ddlst">下拉控件</param>
/// <param name="dt">源DataTable</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
public
static
void
CreateLevelDropDown(DropDownList ddlst, DataTable dt,
string
text,
string
value,
string
parentid)
{
ArrayList allItems =
new
ArrayList();
DataRow[] rows = dt.Select(parentid +
"=0"
);
foreach
(DataRow row
in
rows)
CreateLevelDropDownAssistant(dt,
ref
allItems, row,
string
.Empty, text, value, parentid);
ListItem[] items =
new
ListItem[allItems.Count];
allItems.CopyTo(items);
ddlst.Items.AddRange(items);
}
/// <summary>
/// 递归绑定子节点
/// </summary>
/// <param name="dt">源DataTable</param>
/// <param name="items">数组</param>
/// <param name="parentRow">当前节点</param>
/// <param name="curHeader">前缀</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
private
static
void
CreateLevelDropDownAssistant(DataTable dt,
ref
ArrayList items, DataRow parentRow,
string
curHeader,
string
text,
string
value,
string
parentid)
{
ListItem newItem =
new
ListItem(curHeader + Until.CutString(parentRow[text].ToString(), 18,
true
), parentRow[value].ToString());
items.Add(newItem);
DataRow[] rows = dt.Select(parentid +
"="
+ newItem.Value);
for
(
int
i = 0; i < rows.Length - 1; i++)
CreateLevelDropDownAssistant(dt,
ref
items, rows[i], curHeader.Replace(
"┣"
,
"┃"
).Replace(
"┗"
,
"┣"
) +
"┣"
, text, value, parentid);
if
(rows.Length > 0)
CreateLevelDropDownAssistant(dt,
ref
items, rows[rows.Length - 1], curHeader.Replace(
"┣"
,
"┃"
).Replace(
"┗"
,
"┣"
) +
"┗"
, text, value, parentid);
}
#endregion
#region TreeView 无限递归显示层次关系目录树
/// <summary>
/// 创建无限分级目录树TreeView
/// </summary>
/// <param name="treeview">TreeView空间</param>
/// <param name="dt">数据源DataTable</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
public
static
void
CreateLevelTreeView(TreeView treeview, DataTable dt,
string
text,
string
value,
string
parentid)
{
DataView dv = dt.DefaultView;
dv.RowFilter = parentid +
"=0"
;
foreach
(DataRowView drv
in
dv)
{
TreeNode node =
new
TreeNode();
node.Text = drv[text].ToString();
node.Value = drv[value].ToString();
node.Expanded =
false
;
treeview.Nodes.Add(node);
CreatTreeViewChildNode(dv, node, text, value, parentid);
}
}
/// <summary>
/// 递归绑定子节点
/// </summary>
/// <param name="dv">源DataView</param>
/// <param name="parentNode">当前节点</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
private
static
void
CreatTreeViewChildNode(DataView dv, TreeNode parentNode,
string
text,
string
value,
string
parentid)
{
dv.RowFilter = parentid +
"="
+ parentNode.Value;
foreach
(DataRowView row
in
dv)
{
TreeNode replyNode =
new
TreeNode();
replyNode.Text = row[text].ToString();
replyNode.Value = row[value].ToString();
replyNode.Expanded =
false
;
parentNode.ChildNodes.Add(replyNode);
CreatTreeViewChildNode(dv, replyNode, text, value, parentid);
}
}
/// <summary>
/// 创建无限分级目录树TreeView
/// </summary>
/// <param name="treeview">TreeView空间</param>
/// <param name="dt">数据源DataTable</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="url">url字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
public
static
void
CreateLevelTreeView(TreeView treeview, DataTable dt,
string
text,
string
value,
string
url,
string
parentid)
{
DataView dv = dt.DefaultView;
dv.RowFilter = parentid +
"=0"
;
foreach
(DataRowView drv
in
dv)
{
TreeNode node =
new
TreeNode();
node.Text = drv[text].ToString();
node.Value = drv[value].ToString();
node.NavigateUrl = drv[url].ToString();
node.Expanded =
false
;
treeview.Nodes.Add(node);
CreatTreeViewChildNode(dv, node, text, value, url, parentid);
}
}
/// <summary>
/// 递归绑定子节点
/// </summary>
/// <param name="dv">源DataView</param>
/// <param name="parentNode">当前节点</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="url">url字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
private
static
void
CreatTreeViewChildNode(DataView dv, TreeNode parentNode,
string
text,
string
value,
string
url,
string
parentid)
{
dv.RowFilter = parentid +
"="
+ parentNode.Value;
foreach
(DataRowView row
in
dv)
{
TreeNode replyNode =
new
TreeNode();
replyNode.Text = row[text].ToString();
replyNode.Value = row[value].ToString();
replyNode.NavigateUrl = row[url].ToString();
replyNode.Expanded =
false
;
parentNode.ChildNodes.Add(replyNode);
CreatTreeViewChildNode(dv, replyNode, text, value, url, parentid);
}
}
#endregion
#region 创建无限分级ListBox
/// <summary>
/// 创建无限分级ListBox
/// </summary>
/// <param name="ddlst">ListBox控件</param>
/// <param name="dt">源DataTable</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
public
static
void
CreateLevelListBox(ListBox ddlst, DataTable dt,
string
text,
string
value,
string
parentid)
{
ArrayList allItems =
new
ArrayList();
DataRow[] rows = dt.Select(parentid +
"=0"
);
foreach
(DataRow row
in
rows)
CreateLevelListBoxAssistant(dt,
ref
allItems, row,
string
.Empty, text, value, parentid);
ListItem[] items =
new
ListItem[allItems.Count];
allItems.CopyTo(items);
ddlst.Items.AddRange(items);
}
/// <summary>
/// 递归绑定子节点
/// </summary>
/// <param name="dt">源DataTable</param>
/// <param name="items">数组</param>
/// <param name="parentRow">当前节点</param>
/// <param name="curHeader">前缀</param>
/// <param name="text">text字段</param>
/// <param name="value">value字段</param>
/// <param name="parentid">深度字段 例如parentid</param>
private
static
void
CreateLevelListBoxAssistant(DataTable dt,
ref
ArrayList items, DataRow parentRow,
string
curHeader,
string
text,
string
value,
string
parentid)
{
ListItem newItem =
new
ListItem(curHeader + Until.CutString(parentRow[text].ToString(), 18,
true
), parentRow[value].ToString());
items.Add(newItem);
DataRow[] rows = dt.Select(parentid +
"="
+ newItem.Value);
for
(
int
i = 0; i < rows.Length - 1; i++)
CreateLevelListBoxAssistant(dt,
ref
items, rows[i], curHeader.Replace(
"┣"
,
"┃"
).Replace(
"┗"
,
"┣"
) +
"┣"
, text, value, parentid);
if
(rows.Length > 0)
CreateLevelListBoxAssistant(dt,
ref
items, rows[rows.Length - 1], curHeader.Replace(
"┣"
,
"┃"
).Replace(
"┗"
,
"┣"
) +
"┗"
, text, value, parentid);
}
#endregion
|
希望本文所述对大家asp.net程序设计有所帮助.
最后此篇关于asp.net实现DropDownList,TreeView,ListBox的无限极分类目录树的文章就讲到这里了,如果你想了解更多关于asp.net实现DropDownList,TreeView,ListBox的无限极分类目录树的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在寻找绘制极坐标数据的替代方法。我需要实现像 this 这样的图表具有动态选项,例如 this . 非常感谢您的帮助! 最佳答案 我个人需要这些: Highcharts JS canvasXpre
我是一名优秀的程序员,十分优秀!