[英]Storing data retrieved from web service reference as array/arraylist
I am now doing a silverlight application, language is C# and I have successfully retrieved the data from web service reference and is able to display it on the mainpage.xaml in grid view. I am now doing a silverlight application, language is C# and I have successfully retrieved the data from web service reference and is able to display it on the mainpage.xaml in grid view. However is there any way for me to store my data as array/arraylist so that instead of displaying all the column data in the grid view, I only want it to display only one column of data.
但是,我有什么方法可以将我的数据存储为数组/数组列表,这样我就不想在网格视图中显示所有列数据,而只希望它只显示一列数据。 Any experts that can help me out on this?
有没有专家可以帮助我解决这个问题? Below is my current basic code
以下是我当前的基本代码
[OperationContract]
public List<location> Getlocations()
{
DataClassesDBDataContext db = new DataClassesDBDataContext();
var mlocations = from location in db.locations
select location;
return mlocations.ToList();
}
if you are using wcf service you have a ability to change the return type.如果您使用 wcf 服务,您可以更改返回类型。
In Add Service Reference click on the "Advanced" button at the bottom.在添加服务参考中,单击底部的“高级”按钮。 A new modal dialog box opens "Service reference settings" there you can select "Collection Type" as Arraylist/Array/List.
一个新的模态对话框打开“服务参考设置”,您可以将 select“集合类型”设置为 Arraylist/Array/List。
Now whenever you return List from web method you will receive the one which you have selected in "Collection Type".(This is only available in wcf web service (.svc) and not (.asmx)现在,每当您从 web 方法返回列表时,您将收到您在“集合类型”中选择的列表。(这仅在 wcf web 服务中可用)而不是(.svcm)(。
If that is not a option then you can just change the list to array.如果这不是一个选项,那么您可以将列表更改为数组。
var list = new List<string>{"1","2"}
string[] arrayVal =" list.ToArray();
As the question is not very clear and you say you only want to show one column in the grid you can just return one column data while returning from the web methods like由于问题不是很清楚,并且您说您只想在网格中显示一列,您可以只返回一列数据,同时从 web 方法返回,例如
[OperationContract]
public List<location> Getlocations()
{
var db = new DataClassesDBDataContext();
var mlocations = (from x in db.locations
select new location
{
locationColName = x.something
}).ToList();
return mlocations;
}
The ToArray() method used on the list should do the trick.列表中使用的 ToArray() 方法应该可以解决问题。 A simple general example is shown here:
此处显示了一个简单的通用示例:
List<string> l = new List<string>();
l.Add("somedata");
. . .
string[] s = l.ToArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.