This example demonstrates how to bind ASPxTreeView to data stored in DataTable. Nodes are created in unbound mode.
protected void Page_Load(object sender, EventArgs e) {
DataTable table = GetDataTable();
if (!IsPostBack)
CreateTreeViewNodesRecursive(table, this.treeView.Nodes, "0");
}
private void CreateTreeViewNodesRecursive(DataTable table, TreeViewNodeCollection nodesCollection, string parentID) {
for (int i = 0; i < table.Rows.Count; i++) {
if (table.Rows[i]["ParentID"].ToString() == parentID) {
TreeViewNode node = new TreeViewNode(table.Rows[i]["Title"].ToString(), table.Rows[i]["ID"].ToString());
nodesCollection.Add(node);
CreateTreeViewNodesRecursive(table, node.Nodes, node.Name);
}
}
}
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)