Code to navigate Catalog categories on an ASP.NET Web form
Use the following code to navigate through catalog categories on an ASP.NET Web form. The code sample should be used within a Commerce Server project. For more information about creating a Commerce Server project, see Creating a Commerce Project.
<%@ Page Language="C#" Trace="False" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Catalog" %>
<%@ Import Namespace="System.Data" %>
<script language="C#" >
CatalogContext catalogCtx = CommerceContext.Current.CatalogSystem;
string catalogName = @"Adventure Works Catalog";
void Page_Load(object source, EventArgs args) {
if (!IsPostBack) {
UpdateCategories();
}
}
void RootCategoryListing_ItemCommand(object source, RepeaterCommandEventArgs args) {
SelectedCategory.Text = @"You selected <b>" + args.CommandArgument + "</b>";
}
void UpdateCategories() {
RootCategoryListing.DataSource = catalogCtx.GetCatalog(catalogName).GetRootCategories();
RootCategoryListing.DataBind();
}
</script>
<html>
<head>
<title>List Categories</title>
</head>
<body>
<form >
<asp:Label
id="SelectedCategory"
Text="No category selected"
/><br/><br/>
<asp:Repeater
id="RootCategoryListing"
OnItemCommand="RootCategoryListing_ItemCommand"
>
<HeaderTemplate>
<h2>Categories:</h2>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton
id="SelectCategoryBtn"
CommandName="Select"
CommandArgument='<%# ((DataRowView)Container.DataItem)["CategoryName"] %>'
>
<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>
</asp:LinkButton>
</ItemTemplate>
<SeparatorTemplate>
<p/>
</SeparatorTemplate>
</asp:Repeater>
</form>
</body>
</html>
See Also
Microsoft.CommerceServer.Runtime.Catalog
Copyright © 2005 Microsoft Corporation.
All rights reserved.