FineUI 官方论坛
标题:
树节点
[打印本页]
作者:
MZH
时间:
2012-11-22 07:46
标题:
树节点
public partial class tree_datatable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
private void LoadData()
{
// 模拟从数据库返回数据表
DataTable table = CreateDataTable();
DataSet ds = new DataSet();
ds.Tables.Add(table);
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["ParentId"], false);
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["ParentId"].ToString() == "0")
{
ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
node.Text = "<a href='showcar.aspx'>" + row["Text"].ToString() + "</a>";
node.Expanded = true;
Tree1.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
private void ResolveSubTree(DataRow dataRow, ExtAspNet.TreeNode treeNode)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");
if (rows.Length > 0)
{
treeNode.Expanded = true;
foreach (DataRow row in rows)
{
ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
node.Text = "<a href='showcar.aspx'>" + row["Text"].ToString() + "</a>";
treeNode.Nodes.Add(node);
ResolveSubTree(row, node);
}
}
}
#region CreateDataTable
private DataTable CreateDataTable()
{
DataTable dt = new Test().GetList("");
return dt;
}
#endregion
}
[attach]1304[/attach]
怎么样实现左边这种效果的
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/)
Powered by Discuz! X3.4