Share via


How to Access Site Terms in a Commerce Server Site

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

You access site terms in your Commerce Server site code by using the ProfileContext object. This topic shows how to override the default Render method for a Web form and write all site terms to the form by using HTML.

To access site terms and write them to a Web page

  1. Create a procedure to override the default Render method.

  2. Inside the Render method, create an instance of the Commerce Server ProfileContext runtime object.

  3. Write a begin tag.

  4. For each site term in the site terms collection, write the name of the site term. Each site term must be enclosed in a begin and end tag pair.

  5. For each site term, write the name of the site term elements. Each site term element must be enclosed in a begin and end tag pair.

  6. Write an end tag.

Example

protected override void Render(HtmlTextWriter writer)
{
    ProfileContext ctxt = CommerceContext.Current.ProfileSystem;
    writer.RenderBeginTag(HtmlTextWriterTag.Ul);
    foreach (string siteTermName in ctxt.SiteTermNames)
    {
        SiteTerm siteTerm = ctxt.GetSiteTerm(siteTermName);
        writer.RenderBeginTag(HtmlTextWriterTag.Li);
        writer.Write(siteTerm.Name);
        writer.RenderBeginTag(HtmlTextWriterTag.Ul);
        foreach (SiteTermElement element in siteTerm.Elements)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Li);
            writer.Write(element.Name + " = " + element.Value);
            writer.RenderEndTag();
        }
        writer.RenderEndTag();
    }
    writer.RenderEndTag();
}

Compiling the Code

To compile the code, you must include these namespace directives:

using System.Web.UI;
using System.Web.UI.WebControls;

See Also

Other Resources

How to Use Site Terms

Site Terms Concepts and Tasks