Click here to Skip to main content
16,012,352 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Bind a value from services to Drop down List.
Posted
Comments
[no name] 22-May-13 6:59am    
If your "question" is a single sentence then chances are that:
1. You have not read the FAQ, http://www.codeproject.com/Articles/64628/Code-Project-Quick-Answers-FAQ
2. You have not described what it is that you are trying to do in sufficient detail
3. You have not described what it is that you have tried to do yourself in sufficient detail
4. You have not described any kind of a problem with your code in sufficient detail
5. You have not done any research at all.
6. All of the above.

1 solution

First, get the data from the service and assign it to a container such a collection list. Then iterate trhough the collection, and assign the value to the dropdown list. In the example below, assume that you want to return a list of Status to your dropdown list (ddlStatus).

You can also assign the data returned from the service directly to the dropdown list as the ddlStatus.DataSource, and then bind it (see example 2).

Example 1:
C#
ServiceReference1.ProductServiceClient obj = new ServiceReference1.ProductServiceClient();
           List<lookupoption> statusLookupOptions = obj.GetStatusLookup();

            if (statusLookupOptions  != null)
            {
                foreach (LookupOptionItem lookupOperationStatusItem in statusLookupOptions .LookupOptionItems)
                {
                    ddlStatus.Items.Add(new ListItem(lookupOperationStatusItem.DisplayText, lookupOperationStatusItem.ID.ToString()));
                }
            }</lookupoption>


Example 2:
C#
//Fill drop down list
         ddlStatus.DataSource = obj.GetStatusLookup();
         ddlStatus.DataTextField="TitleColumn";
         ddlStatus.DataValueField="ValueColumn";
         ddlStatus.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900