views:

1452

answers:

2

I am making a RIA application using silverlight and web services the method of a web service returns a DataSet (a classic asp.net dataset which is find in system.data) . Now my problem is:

How to bind a DataGrid of Silverlight with that Dataset which is returned by the Web service

If i am going wrong way do correct me.

If i am right then tell me how to proceed

++ Thanks and Regards Meetu Choudhary

A: 

I think you are going to struggle, given SL's access to the system.data is limited at best, you get System.Data.Services but that doesn't contain the dataset you are talking about.

If you are returning the data from a WCF service, then I would suggest the normal way is to define a data contract class with properties for each field etc and your WCF service method return a collection of that class.

On the proxy side, the auto generated proxy will see this as a List or ObservableCollection and you can then bind to that. That end's up being a bit dirty though since you want logic and to implement INotifyPropertyChanged and various other pieces, so you may well end up transferring the data out of the collection you are given into a local class that is acting as the VM, for the view to bind to.

Andrew
+1  A: 

Dataset is not supported in SL. If You have fixed datasource then you can create data contract (property class) and transfer data by observable collection which you can easily bind with your datagrid.

But if you want something generic which you would like to bind with your SL Datagrid then in that case you have to create Collection of collection

IEnumerable> LData = new List>(); while (sdrdr.Read()) { dict = new Dictionary(); for (int i = 0; i < sdrdr.FieldCount; i++) { dict.Add(sdrdr.GetName(i), sdrdr[i].ToString()); } yield return dict; }

and then you have to create anonymous type with reflection.emit in SL application which you can bind with your SL Datagrid.

Harryboy
Dataset is not supported in SL. If You have fixed datasource then you can create data contract (property class) and transfer data by observable collection which you can easily bind with your datagrid.can you please explain this What is data contract (property class) and observable collection when, where and why to use these
Meetu Choudhary