The CrmMetadataDataSource control is an custom server control that supplies data-bound controls with read-only metadata from CRM. The most common and useful purposes of the control is to bind a ASP.NET DropDownList control to a CRM Option Set.

Retrieve Single Entity Option Set Attribute Metadata

The following example demonstrates using the CrmMetadataDataSource control to bind the options of the Customer Satisfaction Code Option Set attribute of the CRM Incident/Case entity to a databound control.

Option Set DropDownList

<crm:CrmMetadataDataSource ID="SatisfactionSource" runat="server" 
	AttributeName="customersatisfactioncode" 
	EntityName="incident"
	SortExpression="Label DESC" />
<asp:Label AssociatedControlID="Satisfaction" runat="server" Text="Satisfaction" />
<asp:DropDownList ID="Satisfaction" runat="server"
	DataSourceID="SatisfactionSource"
	DataTextField="OptionLabel"
	DataValueField="OptionValue" />

Retrieve Single Entity Attributes Metadata

The following example demonstrates using the CrmMetadataDataSource control to bind the attributes metadata of the CRM Lead entity to a ASP.NET GridView control.

Partial listing of the lead attributes

<crm:CrmMetadataDataSource ID="MetadataDataSource" runat="server"
	EntityName="lead" EntityFlags="All" />
<asp:GridView runat="server" DataSourceID="MetadataDataSource"></asp:GridView>

Control Properties

The CrmMetadataDataSource control has several properties that can be specified to modify the behavior.

NameDescription
EntityName The logical name of the entity to retrieve the metadata from.
AttributeName The logical name of the attribute on the entity to retrieve the attribute metadata from. 
EntityFlags

One of the following:

  • All
  • Attributes
  • Default
  • Entity
  • Privileges
  • Relationships
MetadataFlags

One of the following:

  • All
  • Attributes
  • Default
  • Entity
  • Privileges
  • Relationships
SortExpression

One of the following:

  • ASC
  • DESC