Fill Asp.Net DropDown Values with MS CRM Optionset Meta Data

Retrieve Optionset MetaData using CRM Service and Fill Asp.Net Drop Down Dynamically Using C#

 

public Dictionary<int, string> RetrieveOptionsetMetadata(IOrganizationService service)
{
//Dictionary to store value and text

Dictionary<int,string> AspDropdownDatasource= new Dictionary<int,string>();

//Create request to fetch optionset

RetrieveAttributeRequest RetAttRequest = new RetrieveAttributeRequest
{
EntityLogicalName =”EntityName”,
LogicalName =”OptionsetFieldName”,
RetrieveAsIfPublished =true
};

// Execute the request

RetrieveAttributeResponse RetAttResponse = (RetrieveAttributeResponse)service.Execute(RetAttRequest);

PicklistAttributeMetadata _PicklistAttributeMetadata = (PicklistAttributeMetadata)RetAttResponse.AttributeMetadata;
OptionMetadata[] optionList =_PicklistAttributeMetadata.OptionSet.Options.ToArray();

foreach (OptionMetadata _Optionset in optionList)
{
AspDropdownDatasource.Add(int.Parse(_Optionset.Value.ToString()), _Optionset.Label.UserLocalizedLabel.Label);
}
return AspDropdownDatasource;
}

 

Cheers,

Advertisements

One thought on “Fill Asp.Net DropDown Values with MS CRM Optionset Meta Data

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s