Show MS CRM 2011/2013 Optionset values in Dropdownlist in Asp.net

I’m feeling really happy while writing this blog, because i have been too busy from last couple of months to write even a single blog. From now on, I’m hoping to keep this activity continued.

Few days back i got a very interesting requirement from one of my customer to show OptionSet values in dropdownlist in asp.net.
So we can use below code to populate optionset values in dropdownlist in asp.net Windowor Web application.

As shown below \’Stream\’  field  is being showing in CRM Contact form :





public Dictionary<intstring>
RetrieveOptionsetMetadata(IOrganizationService _iOgranizationService)

{  
//Dictionary to store value and text
 Dictionary<int,string> _DropdownDatasource=newDictionary<int,string>();
 //Create request to fetch optionset
 RetrieveAttributeRequest _Request = new RetrieveAttributeRequest{
EntityLogicalName =\”contact\”,    // Name of Entity
LogicalName =“new_stream”,    // Name of Option Set field
RetrieveAsIfPublished =true
 };
 // Execute the request
 RetrieveAttributeResponse _Response =(RetrieveAttributeResponse)_iOgranizationService.Execute(_Request);
 PicklistAttributeMetadata _PicklistAttributeMetadata = (PicklistAttributeMetadata)_Response.AttributeMetadata;
 OptionMetadata[] optionList =_PicklistAttributeMetadata.OptionSet.Options.ToArray();
 foreach (OptionMetadata _Optionset in optionList) {
_DropdownDatasource.Add(int.Parse(_Optionset.Value.ToString()), _Optionset.Label.UserLocalizedLabel.Label);
}
 return _DropdownDatasource;
}
After that we can set datasource for dropdownlist like below
DropDownList1.DataSource = RetrieveOptionsetMetadata(_iOgranizationService);
DropDownList1.DataBind();

In ASP.Net it will look like below:

Enjoy !!!
Hope this post help someone !!!

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

2 thoughts on “Show MS CRM 2011/2013 Optionset values in Dropdownlist in Asp.net

  1. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

  2. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

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 )

Connecting to %s

%d bloggers like this: