CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeff Lynch [MVP]

Everything E-Commerce!

Commerce Server 2007: Development Tip #4 - Returning Site Terms

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;       
    }


Published Jan 08 2008, 06:00 PM by jlynch
Filed under:

Comments

Add News said:

Data binding is a wonderful thing. Thanks.
# March 7, 2008 1:47 AM

jlynch said:

It is indeed!

Jeff

# May 7, 2008 9:38 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News