<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head runat="server">
<title>Populating Menu Items 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 ) {
if ( ! IsPostBack ) {
DataTable tblCatalogs = fetchData
( "SELECT mode, catalogue, tops FROM ecs_catalogues ORDER BY catalogue", "shop" ).Tables [ 0 ];
foreach ( DataRow row in tblCatalogs.Rows ) {
MenuItem newItem = new MenuItem ( row [ "catalogue" ].ToString ( ),
row [ "tops" ].ToString ( ) );
newItem.NavigateUrl = string.Format (
"https://www.amazon.com/s?k={0}&linkCode=ll2&tag=rvnunz0525-20", row [ "mode" ] );
newItem.Target = "amzn";
catalogsMenu.Items.Add ( newItem );
getCategories ( newItem );
}
}
}
void getCategories ( MenuItem menuItem ) {
string groupnode = menuItem.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 ) {
MenuItem newItem = new MenuItem ( row [ "category" ].ToString ( ),
row [ "browsenode" ].ToString ( ) );
newItem.NavigateUrl = string.Format (
"https://www.amazon.com/b?node={0}&linkCode=ll2&tag=rvnunz0525-20", newItem.Value );
newItem.Target = "amzn";
menuItem.ChildItems.Add ( newItem );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>Populating <span class="hilite">Menu Items</span> from a Database</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<form runat="server">
<div style="margin-left:100"
<asp:menu id="catalogsMenu" runat="server" target="_amzn">
<staticmenustyle
backcolor="ghostwhite"
horizontalpadding=5
borderstyle="outset"
borderwidth=1 />
<dynamicmenustyle
backcolor="ghostwhite"
horizontalpadding=5
verticalpadding=5
borderstyle="outset"
borderwidth=1 />
<statichoverstyle
backcolor="khaki" />
<dynamichoverstyle
backcolor="khaki" />
</asp:menu>
</div>
</form>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>