locked
How to populate CRM 2011 Lookup values to a .net Dropdown list ? RRS feed

  • Question

  • Hello,

    i want to know that How to populate CRM 2011 Lookup values to a .net Dropdown list ?

    Please help!!!


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Saturday, November 23, 2013 8:15 PM

Answers

  • Hi,

    You need to query country entity not offered entity.
    It should be like that :

    QueryExpression query = new QueryExpression("new_country");
    query.ColumnSet = new ColumnSet("new_name");
    EntityCollection result = _iOgranizationService.RetrieveMultiple(query);

    foreach (Entity country in result.Entities)
    {
    if (country.Attributes.Contains("new_name"))
    {
    ddlCountry.Items.Add(country.Attributes["new_name"].ToString());

    }
    }



    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

    • Marked as answer by DynamicsCRM31 Sunday, November 24, 2013 5:27 PM
    Sunday, November 24, 2013 1:59 AM

All replies

  • Hi,

    How to populate asp.net dropdownlist with CRM 2011 Lookup Attribute ?

    Response would be appreciated.!!


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Saturday, November 23, 2013 4:14 PM
  • Hi,

    Please check the following link to connect to CRM from web application 

    http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/

    You could use following sample code to populate entire accounts records.

    Note : sometime we are using filtered lookups, for that case you need to add conditions on the QueryExpression.

                QueryExpression query = new QueryExpression("account");
                query.ColumnSet = new ColumnSet("name");
                EntityCollection result = service.RetrieveMultiple(query);

                foreach (Entity account in result.Entities)
                {
                    DropDownList1.Items.Add(account.Attributes["name"].ToString());
                }


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !


    • Edited by _Vikram Saturday, November 23, 2013 4:35 PM
    Saturday, November 23, 2013 4:35 PM
  • Hi,

    As in my case there is a lookup of country name "new_country" on "new_offer" entity form.

    So i wrote like..

        QueryExpression query = new QueryExpression("new_offered");
                query.ColumnSet = new ColumnSet("new_country");
                EntityCollection result = _iOgranizationService.RetrieveMultiple(query);

                foreach (Entity country in result.Entities)
                {
                    if (country.Attributes.Contains("new_country"))
                    {
                        ddlCountry.Items.Add(((EntityReference)(country.Attributes["new_country"])).Name);
                    }
                }

    What happenes that lot of duplicate entries there in dropdown.. Not actual crm Country lookup items,there are only 4 Country in lookup.

    Where am i going wrong ?


    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Saturday, November 23, 2013 5:45 PM
  • Hi,

    You need to query country entity not offered entity.
    It should be like that :

    QueryExpression query = new QueryExpression("new_country");
    query.ColumnSet = new ColumnSet("new_name");
    EntityCollection result = _iOgranizationService.RetrieveMultiple(query);

    foreach (Entity country in result.Entities)
    {
    if (country.Attributes.Contains("new_name"))
    {
    ddlCountry.Items.Add(country.Attributes["new_name"].ToString());

    }
    }



    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

    • Marked as answer by DynamicsCRM31 Sunday, November 24, 2013 5:27 PM
    Sunday, November 24, 2013 1:59 AM
  • Please don't create duplicate threads : http://social.microsoft.com/Forums/en-US/91eccdfd-0ae0-4cc0-848f-cba8f1141425/how-to-populate-aspnet-dropdownlist-with-crm-2011-lookup-attribute-?forum=crm

    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !


    • Edited by _Vikram Sunday, November 24, 2013 2:44 AM
    Sunday, November 24, 2013 2:43 AM
  • Thanks Vikram !!!

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, November 24, 2013 5:27 PM