如何为服务中的下拉列表分配值。 [英] How to Assign a value to Dropdown From a services.

查看:59
本文介绍了如何为服务中的下拉列表分配值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将服务中的值绑定到下拉列表。

How to Bind a value from services to Drop down List.

推荐答案

首先,从服务获取数据并将其分配给容器这样的集合列表。然后迭代集合,并将值分配给下拉列表。在下面的示例中,假设您要将状态列表返回到下拉列表(ddlStatus)。



您还可以将服务返回的数据直接分配给下拉列表作为ddlStatus.DataSource,然后绑定它(参见示例2)。



示例1:

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:
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>





示例2:



Example 2:

//Fill drop down list
         ddlStatus.DataSource = obj.GetStatusLookup();
         ddlStatus.DataTextField="TitleColumn";
         ddlStatus.DataValueField="ValueColumn";
         ddlStatus.DataBind();


这篇关于如何为服务中的下拉列表分配值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆