Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Binding Collection Class from Business Layer to a Control in Presentation Layer
6 replies. Latest Post by silverlight programmer on April 1, 2009.
(0)
silverli...
Member
0 points
5 Posts
03-25-2009 11:00 PM |
Hi,
I have to bind the collection class to my datagrid, but my datagrid is in Presentation Layer, I am calling the WCF service in Business Layer, how do I do this..?
proxy.GetDataAsync();
{
//--e.Result;
//--- this is my result, how do I bind this result to my datagrid. If I call the service from Presentation layer, I can directly bind the result to datagrid as below:
mydatagrid.ItemSource=e.Result;
Need some help on this.
Thanks in Advance.
gv_pradeep
28 points
25 Posts
03-26-2009 12:51 AM |
I guess there are many ways to achieve this.
You can define the Event Handler method in your presentation layer and hook up the event to the event handler.
proxy.GetData + = new EventHandler<GetDataCompletedEventArgs>(presentationLayer.proxy_GetDataCompleted)
In this method, you can then directly bind the result to your datagrid.
03-31-2009 1:50 AM |
Thanks for your reply.
I cannot define the Event handler in Presentation Layer because I have to consume the WCF service in my Business Layer. I have to make a call to database from my business layer only, so I want to know how to return the Collection class to my presentation layer from Business layer in order to bind to my control.
Any ideas please..?
kranthi....
237 points
42 Posts
03-31-2009 2:07 AM |
What you are returning from business layer?
I mean e.Result is of which Type, is it in xml format or you are passing objects from business layer to presentation layer
If e.Result type is xml format then you can convert it into object and bind it to datagrid as shown below:
items = (
now you can bind the items to the datagrid
03-31-2009 2:39 AM |
I am returning the Generic collection class from business layer, I mean e.result returns the collection class. The following code I perform in business layer, but proxy_GetDataCompleted method below is void, cannot return anything, how can I pass the collection class to my presentation control. It doesn't matter me whether e.result is an XML or collection class, my problem is I am unable to pass the output collection class from my business layer to presentation layer.
MyServiceClient proxy= new MyServiceClient ();
//--e.Result; I get the result here, but I cannot pass the result to presentation layer here, since this is void.
Amanda W...
All-Star
17241 points
1,466 Posts
03-31-2009 5:03 AM |
Hi silverlight programmer,We would suggest that you can try to convert the e.results into an ObservableCollection, so you can try to exposed this ObservableCollection object and then you can access it in the presentation layer:for example:public ObservableCollection data;void proxy_GetDataCompleted(object sender, GetDataCompletedEventArgs e){//--e.Result; I get the result here, but I cannot pass the result to presentation layer here, since this is void. foreach (var person in e.Result) { data.Add(person); } }
04-01-2009 4:43 PM |
Hi Amanda,
Thanks for your reply, I have tried this way before I post this query here, but was not successful.
public ObservableCollection<MyClass> myresult= new ObservableCollection<MyClass>();
//--Calling the Service here Public void callService(){ MyServiceClient proxy= new MyServiceClient ();
proxy.GetData += new EventHandler<GetDataCompletedEventArgs>(proxy_GetDataCompleted);
proxy.GetDataAsync(); 1. After this line gets executed, then it jumps directly from where the call has been made and the collection classwhich I declared globally returns null/nothing at this point of time, after this only proxy_GetDataCompleted() method gets executed, but I cannot pass the collection class results to my presentation layer.
2. In short, I am not able to assign the results to the collection class which is declared globally to pass the results to presentation layer.
3. //-- myresult.Add(new MyClass() { FirstName= "XXXX", LastName = YYYY}); //-- This line of code is for testing purpose, I have checked whether the values assigned to my collection class holds results or not, it holds the results here.
}
void proxy_GetDataCompleted(object sender, GetDataCompletedEventArgs e) { foreach (var res in e.Result) { myresult.Add(new MyClass() { FirstName = res.FirstName, LastName = res.LastName }); }