2012-06-07 36 views
2

我确信这是可能的,我只是没有弄清楚如何或从哪里开始。如何将.net下拉列表绑定到CRM 2011选项集

所以,我有一个MS动态CRM中创建的选项集,它给了我一个国家名单MyCountryOptionSet。可爱。

但是,我有许多其他.net,c#应用程序,用户可以输入自由文本。这不太可爱。

因此,我想将这些关联起来,以便只能使用MyCountryOptionSet中的国家。

因此,我想将MyCountryOptionSet中的国家绑定到我的.net应用程序中的下拉列表中。

我该怎么做呢?

+1

这一点,你挣扎?从CRM获取选项列表还是将这些数据绑定到您的控件? –

+0

格雷格对不起 - 获取CRM的选项列表。 –

+0

不要道歉里卡多 - 这只是为了我们可以帮助你更容易:) –

回答

5

调查RetrieveAttributeRequestIOrganizationService。这将允许您获取选项集中定义的国家/地区。通过将AttributeMetadata属性施加于对PicklistAttributeMetadata的响应。

绑定到控件将是UI技术特定的,所以发布更多信息。

+0

+1“对控件的绑定将是UI技术特定的,因此**发布更多信息**。” –

+1

'PicklistAttributeMetadata'包含一个名为'OptionSet'(类型为'OptionSetMetadata')的属性,该属性又具有一个名为'Options'的属性,它从'DataCollection'继承。这可以在CRM SDK [链接]中找到(http://msdn.microsoft.com/en-us/library/microsoft.xrm.sdk.metadata.picklistattributemetadata) –

0

您可以直接查询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 

一旦有了结果,你可以将它们绑定到你的应用程序列表。

+1

...除非这是一个CRM Online部署(承认OP没有标记他的问题,所以可以安全地认为他是在-premise - 但如果将来有人正在阅读) - 在这种情况下,SQL不是您可以选择的选项。 –

4

使用CRM API来获取选项的值,如下...

_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())); 
} 

然后绑定列表项通用collectoin到乌尔asp.net下拉

相关问题