[c#]代码库
private void LoadData()
{
// 模拟从数据库返回数据表
DataTable table = GetProductTable();
DataSet ds = new DataSet();
ds.Tables.Add(table.Copy());
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["ParentId"]);
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row.IsNull("ParentId"))
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.Text = row["Text"].ToString();
node.NodeID = row["ID"].ToString();
node.EnablePostBack = true;
node.Expanded = true;
ProductTree.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
public DataTable GetProductTable()
{
DataTable ProductTable = Common.NoPager2("factorManagement", "", "ID,Valided,sort_name AS Text,sort_parentID AS ParentId", "ID", "sortType=1 AND Valided=1").Tables[0];
ProductTable.Rows[0]["ParentId"] = DBNull.Value;
return ProductTable;
}
private void ResolveSubTree(DataRow dataRow, FineUI.TreeNode treeNode)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");
if (rows.Length > 0)
{
foreach (DataRow row in rows)
{
DataRow[] ChlidRows = row.GetChildRows("TreeRelation");
if (ChlidRows.Length == 0)
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.EnablePostBack = true;
node.Expanded = false;
node.IconUrl = "../imgs/folder.gif";
node.Text = row["Text"].ToString();
node.NodeID = row["ID"].ToString();
treeNode.Nodes.Add(node);
}
else
{
FineUI.TreeNode node = new FineUI.TreeNode();
node.EnablePostBack = true;
node.Expanded = false;
node.Text = row["Text"].ToString();
node.NodeID = row["ID"].ToString();
treeNode.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
}
by: 发表于:2018-01-03 10:43:42 顶(0) | 踩(0) 回复
??
回复评论