<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head runat="server">
<title>Populating Treeview Nodes from a Database</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="fetchData_oledb.cs" />
<script runat="server">
void Page_Load ( Object source, EventArgs e ) {
DataTable tblCatalogs = fetchData
( "SELECT mode, catalogue, tops FROM ecs_catalogues ORDER BY catalogue", "shop" ).Tables [ 0 ];
foreach ( DataRow row in tblCatalogs.Rows ) {
TreeNode newNode = new TreeNode ( row [ "catalogue" ].ToString ( ),
row [ "tops" ].ToString ( ) );
newNode.NavigateUrl = string.Format (
"https://www.amazon.com/s?k={0}&linkCode=ll2&tag=rvnunz0525-20", row [ "mode" ] );
newNode.Target = "amzn";
myTreeView.Nodes.Add ( newNode );
getCategories ( newNode );
}
}
void getCategories ( TreeNode TreeNode ) {
string groupnode = TreeNode.Value;
DataTable tblCategories = fetchData
( "SELECT mode, category, browsenode FROM ecs_nodes WHERE groupnode = '" +
groupnode + "' ORDER BY category", "shop" ).Tables [ 0 ];
foreach ( DataRow row in tblCategories.Rows ) {
TreeNode newNode = new TreeNode ( row [ "category" ].ToString ( ),
row [ "browsenode" ].ToString ( ) );
newNode.NavigateUrl = string.Format (
"https://www.amazon.com/b?node={0}&linkCode=ll2&tag=rvnunz0525-20", newNode.Value );
newNode.Target = "amzn";
TreeNode.ChildNodes.Add ( newNode );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Populating <span class="hilite">Treeview Nodes</span> from a <span class="hilite">Database</span></h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<form runat="server">
<div style="margin-left:100"
<asp:treeview id="myTreeView" runat="server"
imageset="XPFileExplorer"
showlines expanddepth=0 target="_amzn" />
</div>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>