I'm going to repost this series of "development tips" related to Commerce Server 2007 to help other folks get started with their development work. All of these "tips" come directly from what I've learned (the hard way) over the past eight months and are intended to save you time and effort. All code samples are now based upon the RTM version and have been tested in our production environment.
Tip #4 – Returning Site Terms
One of the really great things about ASP.NET 2.0 is just how easy it is to bind data to server controls like the DropDownList. Commerce Server 2006 includes many new "bindable" collections and custom DataSets which take advantage of this feature of ASP.NET 2.0.
<asp:DropDownList ID="UserRoleDropDownList" DataSourceID="UserRolesDataSource" DataTextField="Name" DataValueField="Value" runat="server" TabIndex="8"></asp:DropDownList>
<asp:ObjectDataSource ID="UserRolesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetUserRoles" TypeName="UserManager"></asp:ObjectDataSource>
In the .aspx code shown above I've created a simple DropDownList bound to an ObjectDataSource which calls the GetUserRoles() select method to return a SiteTermElementCollection (new in CS2007) which can be directly bound to any list control.
public SiteTermElementCollection GetUserRoles()
{
// Get the SiteTermElementCollection for data binding on the site
return CommerceContext.Current.ProfileSystem.GetSiteTerm("user_role").Elements;
}