TreeView的简单应用
html代码
AutoGenerateDataBindings="False" CssClass="tb_tree" ShowLines="True" ExpandDepth="0">
cs代码
private void BindData()
{
DataView dvAll = OperationStartMenu.GetDataView();
dvAll.Sort = "NodeSort";
this.TreeView.Nodes.Clear();
TreeNode root = new TreeNode();
root.Text = "启动业务";
root.Value = "BusinessStart";
root.ImageUrl = "~/images/ftb/folder.small.gif";
if (!Page.IsPostBack)
{
root.Select();
}
this.TreeView.Nodes.Add(root);
this.InitTree(root, dvAll);
this.TreeView.ExpandDepth = 1;
}
protected void InitTree(TreeNode Node, DataView dvAll)
{
dvAll.RowFilter = string.Format("FatherNodeValue='{0}'", Node.Value);
for (int i = 0; i < dvAll.Count; i++)
{
DataRowView drv = dvAll[i];
string NodeText = drv["NodeText"].ToString();
string NodeValue = drv["NodeValue"].ToString();
string NodeSort = drv["NodeSort"].ToString();
string NodeUrl = drv["NodeUrl"].ToString();
TreeNode ChildNode = new TreeNode();
ChildNode.NavigateUrl = NodeUrl;
ChildNode.Text = NodeText;
ChildNode.Value = NodeValue;
if (ChildNode.NavigateUrl.Length == 0)
{
ChildNode.ImageUrl = "~/images/ftb/folder.small.gif";
}
else
{
ChildNode.NavigateUrl = string.Empty;
ChildNode.ImageUrl = "~/images/ftb/office2003/createlink.gif";
}
Node.ChildNodes.Add(ChildNode);
InitTree(ChildNode, dvAll);
dvAll.RowFilter = string.Format("FatherNodeValue='{0}'", Node.Value);
}
}
数据表
名称 |
类型 |
可否空 |
默认值 |
说明 |
ID |
Numeric |
N |
|
自增主键 |
FatherNodeValue |
Varchar2(500) |
N |
父节点标识 |
|
NodeValue |
Varchar2(500) |
N |
节点标识 |
|
NodeMenuID |
Varchar2(20) |
Y |
节点对应的业务菜单ID(若不为空,则根据此项查找对应的URL) |
|
NodeUrl |
Varchar2(200) |
Y |
节点URL |
|
NodeText |
Varchar2(200) |
N |
节点显示名称 |
|
UserID |
Varchar2(20) |
N |
用户ID |
|
NodeSort |
Numeric |
N |
节点顺序 |
|
NodeUrlTarget |
Varchar2(20) |
N |
是否为系统内地址 |
|
IsLeafNode |
Varchar2(20) |
N |
是否为叶节点 |