web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dropdownlist in Asp.net c# crm 2011

(0) ShareShare
ReportReport
Posted on by 155

I created a web application and try to put items from an entity in a dropdownlist.

I also want to populate the value from crm as selected value in de dropdownlist.

Can anyone help me with this.

I tried creating this in code behind, but the selected value is not the value from crm

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Dropdownlist in Asp.net c# crm 2011

    How to insert this value into crm

  • Verified answer
    _Alessandro_ Profile Picture
    615 on at
    RE: Dropdownlist in Asp.net c# crm 2011

    you want to add a reference to a product in your order? (in the lookup)

    then you have to create the entityreference to the product

    EntityReference productEntityReference = new EntityReference(Product.EntityLogicalName, productId);

    where productId is the guid of the product you selected.

    then you put the value in your "order" entity (I don't know if it's a new one or a retrieved one)

    orderentity["productid"] = productId;

    and save or update your entity.

  • Nourdin Profile Picture
    155 on at
    RE: Dropdownlist in Asp.net c# crm 2011

    Hello,

    To set the selected item I used this code :

    EntityReference productlookup = (EntityReference)result1.Entities[0].Attributes["new_ProductList"];

                           new_productid.SelectedValue = productlookup.Id.ToString();

    This worked for me.

    But how can I write this value to to CRM ?

    new_productid.SelectedValue.ToString() doesn't work.

    Many thanks.

  • _Alessandro_ Profile Picture
    615 on at
    RE: Dropdownlist in Asp.net c# crm 2011

    so... you now have the selected ProductID. i did not understand wich value you want to put in the lookup field

  • Nourdin Profile Picture
    155 on at
    RE: Dropdownlist in Asp.net c# crm 2011

    Populating the items in the dropdown isn't an issue.

    This is my code : (Page_Load)

    serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

                   IOrganizationService service = (IOrganizationService)serviceProxy;

                   QueryExpression qeProducts = new QueryExpression("new_product");

                   string[] colsT = { "new_productid", "new_product" };

                   qeProducts.ColumnSet = new ColumnSet(colsP);

                   var products = service.RetrieveMultiple(qeProducts);

                   string Product;

                   Guid ProductID;

                      //Build dropdown

                       for (int iCount = 0; iCount < products.Entities.Count; iCount++)

                       {

                           ProductID = new Guid(products[iCount].Attributes["new_productid"].ToString());

                           Product = products[iCount].Attributes["new_product"].ToString();

                           DropdownProd1.Items.Add(new ListItem(Product.ToString(), ProductID.ToString()));

                           DropdownProd1.DataTextField = Product;

                           DropdownProd1.DataValueField = ProductID.ToString();

                       }

    I have another entity (say orders) where i have a lookup field and I want to put the value of DropdownProd1 in that field.

    Thanks

    I also want the selected value in  the dropdown = the value of it in the order entity.

    Thanks for your help

  • Suggested answer
    _Alessandro_ Profile Picture
    615 on at
    RE: Dropdownlist in Asp.net c# crm 2011

    probably i think that you don't want to populate the dropdownlist with the item from an entity, but from an entitylist, right?

    you have to perform a retrievemultiple to get your entitylist, then you create items of the list with Name and value

    then you select your item ddl.selectedItem = yourItem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans