how to consume entity object from web service

A

Antonio (MCAD)

My question is I have [WebMethod] that returns an array of a object of Type
OrderStatus[]. I am not using datasets, but I want to consume this from the
web application and populate a repeater control. I want to be able to take
this data and filter out certain rows before binding to the repeater. I just
need some example code on the .net 2 web application side to see how to take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

Application Code:
[WebMethod]
public OrderStatus[] GetOrderStatusSummary()
{
return OrderManager.GetOrderStatusSummary();
}


Thank You.
 
J

John Saunders [MVP]

Antonio (MCAD) said:
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
 
A

Antonio (MCAD)

John Saunders said:
Antonio (MCAD) said:
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
 
A

Antonio (MCAD)

John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this, do
you have any links that I can read up on to learn about this area?

thanks Again!

John Saunders said:
Antonio (MCAD) said:
My question is I have [WebMethod] that returns an array of a object of
Type
OrderStatus[]. I am not using datasets, but I want to consume this from
the
web application and populate a repeater control. I want to be able to
take
this data and filter out certain rows before binding to the repeater. I
just
need some example code on the .net 2 web application side to see how to
take
this data and modify it:

This is what I have today:

Presentation Code:
WebService src = new WebService ();
Repeater1.DataSource = src.GetOrderStatusSummary();
Repeater1.DataBind();

You can do this in one of several ways. Here's a simple way:

using (WebService src = new WebService()) // Remember that they implement
IDisposable
{
List<OrderStatus> rawList = new
List<OrderStatus>(src.GetOrderStatusSummary());
List<OrderStatus> filteredList = rawList.FindAll(
delegate(OrderStatus os)
{
if (os.Field1 > 100 && // Your criteria here
os.Field2 == "something")
{
return true;
}
else
{
return false;
}
});
Repeater1.DataSource = filteredList;
Repeater1.DataBind();
}
 
J

John Saunders [MVP]

Antonio (MCAD) said:
John,

That worked perfectly! I have been trying to find examples of this on
google with no luck. You mentioned there are several ways of doing this,
do
you have any links that I can read up on to learn about this area?

Antonio, I'm glad that helped.

I don't really have further links. I'd look at the features of the DataView
class (http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx).
You can load your web service data into a DataSet (I do not recommend that
your web service _return_ a DataSet) and then use a DataView to sort and
filter it. You can then bind to the DataView. This is very flexible.

You can go further than this if necessary, and create a DataSet with
multiple, related tables. Some can come from your web service, some from a
database, some from one or more files. You can create columns in the DataSet
that are calculated from other columns, or even calculated by running totals
across multiple rows. This can get as fancy as you like.

The basic rule I'd use is to keep the web service interface fairly simple,
using arrays instead of ArrayLists or generic lists. Then, load it into
something more convenient on the client side and go wild!
 
A

Antonio (MCAD)

John,

You have been greatful in providing this information. Now i have another
question which leads from the first question.

My webmethod returned the object and with your help i was able to filter the
list and bind it to the appropiate repeater control with no problems. Now i
would like to use the rp1_ItemDataBound event to modify a field of data based
on the results of the other field. So my object from previous example
returns a status field and a quantity field. I want to provide a link to the
status field if the quantity is greater than zero.

I can not figure out how to resolve the field
(WebService.OrderStatus)e.Item.DataItem).Quantity below???

This is what I have:

protected void Repeater1_ItemDataBound(Object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
if (((WebService.OrderStatus)e.Item.DataItem).Quantity > 0)
{
//TODO: Add link to OrderStatus.Status field
}
}
}
 
J

John Saunders [MVP]

Antonio (MCAD) said:
John,

You have been greatful in providing this information. Now i have another
question which leads from the first question.

My webmethod returned the object and with your help i was able to filter
the
list and bind it to the appropiate repeater control with no problems. Now
i
would like to use the rp1_ItemDataBound event to modify a field of data
based
on the results of the other field. So my object from previous example
returns a status field and a quantity field. I want to provide a link to
the
status field if the quantity is greater than zero.

I can not figure out how to resolve the field
(WebService.OrderStatus)e.Item.DataItem).Quantity below???

I'm not sure from your post which problem you're having. Is it that you
can't access the Quantity field, or that you can't add the link? Also, I'm
not sure what you mean when you say "add a link to the status field".
 
A

Antonio (MCAD)

I have figured out my own problem and I am posting it here:

protected void Repeater1_ItemDataBound(Object sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
if (((OrderStatus)e.Item.DataItem).Qty != "0")
{
//TODO: add the hyperlink
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top