Code to list catalogs on an ASP.NET Web form
Use the following code to list catalogs 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#" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime" %>
<%@ Import Namespace="Microsoft.CommerceServer.Runtime.Catalog" %>
<%@ Import Namespace="System.Data" %>
<script language="C#" >
CatalogContext catalogCtx = CommerceContext.Current.CatalogSystem;
void Page_Load(object source, EventArgs args) {
if (!IsPostBack) {
UpdateCatalogs();
}
}
void ChangeCatalogBtn_Click(object source, EventArgs args) {
SelectedCatalog.Text = @"You selected <b>" + CatalogListing.SelectedItem.Text + "</b>";
}
void UpdateCatalogs() {
CatalogListing.DataSource = catalogCtx.CatalogNames;
CatalogListing.DataBind();
}
</script>
<html>
<head>
<title>List Catalogs</title>
</head>
<body>
<form >
<asp:Label
id="SelectedCatalog"
Text="No catalog selected"
/><br/>
<asp:DropDownList
id="CatalogListing"
/>
<asp:Button
id="ChangeCatalogBtn"
OnClick="ChangeCatalogBtn_Click"
Text="OK"
/>
</form>
</body>
</html>
See Also
Microsoft.CommerceServer.Runtime.Catalog
Copyright © 2005 Microsoft Corporation.
All rights reserved.