簡體   English   中英

如何將.net下拉列表綁定到CRM 2011選項集

[英]How to bind a .net dropdown list to a CRM 2011 Option Set

我確信這是可能的,我只是沒有最模糊的方式或從哪里開始。

所以,我在MS Dynamic CRM中創建了一個選項集,它為我提供了一個國家列表MyCountryOptionSet。 可愛。

但是,我有許多其他.net,c#應用程序,用戶可以在其中輸入自由文本。 這不是那么可愛。

因此,我想將它們聯系起來,以便只能使用MyCountryOptionSet中的當前國家/地區。

因此,我想將MyCountryOptionSet中的國家/地區綁定到我的.net應用程序中的下拉列表中。

我該怎么做呢?

查看RetrieveAttributeRequestIOrganizationService 這樣您就可以獲得選項集中定義的國家/地區。 通過在對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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM