简体   繁体   English

如何使用从Web服务获得的arraylist填充下拉列表

[英]How to fill a dropdownlist with arraylist that I get from a web service

I am consuming a java web service in asp.net, the method is an arraylist that devuleve the code and name, and I do not know how to load it to a dropdonwlist in which it shows the name and value is the code. 我正在asp.net中使用Java Web服务,该方法是一个数组列表,用于设计代码和名称,并且我不知道如何将其加载到dropdonwlist中,在其中显示名称和值就是代码。

I tried the following way: 我尝试了以下方法:

WebReferences.agencia datos = new WebReferences.agencia();

listAgencia.DataSource = datos;
listAgencia.DataTextField = datos.nombre;
listAgencia.DataValueField = Convert.ToString(datos.ida);
listAgencia.DataBind();

It gives me error in the datasource. 它给我在数据源中的错误。

As you access properties nombre and ida from datos , it seems that datos isn't a collection but a single object. 当你访问来自DATOS农布雷国际开发协会 ,似乎DATOS不是一个集合,但单个对象。

In this case this would be enough: 在这种情况下,这就足够了:

listaAgencia.Items.Add(new ListItem(datos.nombre, datos.ida.ToString()));

Should datos be a collection, instead, I would do like this: 如果datos是一个集合,我会这样做:

foreach (var singleData in datos)
   listaAgencia.Items.Add(new ListItem(singleData.nombre, singleData.ida.ToString()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从我的 c# web Z8A5DA52ED12065747D359E70A 填写 angular 7 中的材料下拉列表? - How do I fill a material dropdownlist in angular 7 from my c# web api? 如何使用asp.net C#中的Ajax和Web服务使用数据库中的数据填充动态创建的下拉列表 - how fill the dynamically created dropdownlist with data from database using ajax and web service in asp.net c# 从onselectindex填充下拉列表已更改 - fill dropdownlist from onselectindexchanged 在调用填充详细信息网格的方法之前,如何从填充的下拉列表中获取信息? - How do get information from a populated dropdownlist before calling a method to fill the details grid? 如何使用ASP.NET应用程序中的XML文件中的数据填充我的DropDownList - How I can fill my DropDownList with Data from a XML File in my ASP.NET Application 如何用 ASP.NET Core MVC 中的下拉列表中的值填充表格 - How can i fill a table with values from a dropdownlist in ASP.NET Core MVC 如何从下拉列表中获取ID? - How to get id from dropdownlist? 如何从下拉列表中获取价值? - How to get value from Dropdownlist? 如何从控制器中的HTML.DropDownList获取HTML - How do I get the HTML from an HTML.DropDownList in the controller 如何从下拉列表中获取DataValueField? - How to get DataValueField from dropdownlist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM