![](/img/trans.png)
[英]How to set Option List value on new CRM 2011 Entity record with Linq?
[英]How to bind a .net dropdown list to a CRM 2011 Option Set
我确信这是可能的,我只是没有最模糊的方式或从哪里开始。
所以,我在MS Dynamic CRM中创建了一个选项集,它为我提供了一个国家列表MyCountryOptionSet。 可爱。
但是,我有许多其他.net,c#应用程序,用户可以在其中输入自由文本。 这不是那么可爱。
因此,我想将它们联系起来,以便只能使用MyCountryOptionSet中的当前国家/地区。
因此,我想将MyCountryOptionSet中的国家/地区绑定到我的.net应用程序中的下拉列表中。
我该怎么做呢?
查看RetrieveAttributeRequest
和IOrganizationService
。 这样您就可以获得选项集中定义的国家/地区。 通过在对PicklistAttributeMetadata
的响应上转换AttributeMetadata
属性。
对控件的绑定将是UI技术特定的,因此发布更多信息。
使用crm apis获取选项值如下...
_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
serverConfig.Credentials, serverConfig.DeviceCredentials);
_serviceProxy.EnableProxyTypes();
_service = _serviceProxy;
RetrieveAttributeRequest retrieveAttributeRequest =
new RetrieveAttributeRequest
{
EntityLogicalName = EntityLogicalName,
LogicalName = optionSetLogicalName,
RetrieveAsIfPublished = true,
};
// Execute the request.
RetrieveAttributeResponse retrieveAttributeResponse =
(RetrieveAttributeResponse)_service.Execute(
retrieveAttributeRequest);
// Access the retrieved attribute.
PicklistAttributeMetadata retrievedPicklistAttributeMetadata =
(PicklistAttributeMetadata)
retrieveAttributeResponse.AttributeMetadata;
// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
//Dictionary<int,string> LocalizedLabelDic = new Dictionary<int,string>();
List<ListItem> OptionSetItems = new List<ListItem>();
foreach (OptionMetadata o in optionList)
{
OptionSetItems.Add(new ListItem(o.Label.LocalizedLabels.FirstOrDefault(e => e.LanguageCode == 1033).Label.ToString(), o.Value.Value.ToString()));
}
然后将listitem通用collectoin绑定到你的asp.net下拉列表
您可以使用如下查询直接查询CRM数据库中的值:
select Value, AttributeName
from StringMap
where AttributeName = 'New_MySet' --schema name of the global option set
and ObjectTypeCode = 1 --changes based on entity type field is associated with
获得结果后,您可以将它们绑定到应用程序中的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.