开发者

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. 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 开发者_如何学Pythondb.locations
                      select location;
     return mlocations.ToList();
  }


if you are using wcf service you have a ability to change the return type.

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.

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)

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

 [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. A simple general example is shown here:

List<string> l = new List<string>();
l.Add("somedata");
. . .
string[] s = l.ToArray();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜