ASP.NET, DataList, and WebServices

R

Roger R. Smith

Anyway I am having a problem with Web Service and DataList in ASP.NET. so
the best way to explain it would be with the MSPetShop 3.0 Application.
I submitted an order using the Forms on http://localhost/MSPetShop. then I
created my own ASp.NET Project and I have a form on which I have a DataList,
b/c I want to display a bunch of items. BUt for this example I did the
following:

localhost.WebServices webservices = new localhost.WebServices();
localhost.OrderInfo order = webservices.GetOrder(1);
IList orderList = new ArrayList();
orderList.Add(order);
DataList1.DataSource = orderList;
DataList1.DataBind();
I added the Order to an ArrayList just to test, and then on the codebehind I
have the following:
<asp:DataList id="DataList1" style="Z-INDEX: 104; LEFT: 136px; POSITION:
absolute; TOP: 248px"
runat="server">
<HEADERTEMPLATE>
Roger
</HEADERTEMPLATE>
<ItemTemplate>
<TD><%# DataBinder.Eval(Container.DataItem, "OrderId") %></TD>
</ItemTemplate>
</asp:DataList>

but with this I am getting the following error:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinder.Eval:
'WebServicePortal.localhost.OrderInfo' does not contain a property with the
name OrderId.

Source Error:


Line 45: </HEADERTEMPLATE>
Line 46: <ItemTemplate>
Line 47: <TD><%# DataBinder.Eval(Container.DataItem, "OrderId") %></TD>
Line 48: </ItemTemplate>
Line 49: </asp:DataList></P>


This is the same error I am getting on my application.
Any ideas?
 
J

Jan Tielens

Is there a property OrderId on the class you are displaying? Make sure you
have the same casing! (e.g. OrderID is different from OrderId)

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
R

Roger R. Smith

Yes there is in fact in this instance as well as in the instance in my
application.
Rog
 
R

Roger R. Smith

Do I need this statment in your code Jan?

CodeCastExpression castedInnerObject =

new CodeCastExpression("Object",

new CodeVariableReferenceExpression("_innerObject"));



I am getting errors there.

rog
 
R

Roger R. Smith

Ok I modified the reflection code using CodeDom from your srticle for my own
purposes.
so my two questions are from your article :

do I need:
CodeCastExpression castedInnerObject =
new CodeCastExpression("Object",
new CodeVariableReferenceExpression("_innerObject"));
I am not using it now and for what I am doing it seems fine, however I have
really changed your code to fit my own purposes.
Also,
My data is lost, one the new class has been compiled, it shows up in the
DataGrid, but there is no data
Do you have any ideas why I would be losing my data, do I need to assing
like you did in your example:
http://www.microsoft.com/belux/nl/msdn/community/columns/jtielens/webservicewrapper.mspx
//Binding the result to a DataGrid, WITHOUT using the Wrapper.

dataGrid1.DataSource = customers;


//Binding the result to a DataGrid, using the Wrapper.

dataGrid1.DataSource = WebserviceWrapper.Engine.GetWrappedArray(customers);

Thanks a lot Jan, I really appreciate it.
 
J

Jan Tielens

Yes, you do need that line of code. This code will make sure the innerobject
gets casted to the right type. What is the exception you are getting?

You need to use it like this:
//Binding the result to a DataGrid, using the Wrapper.

dataGrid1.DataSource =
WebserviceWrapper.Engine.GetWrappedArray(customers);

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
R

Roger R. Smith

Hi Jan,
basically what happens is if I consume a web service and then I try to use
it in my datagrid, the actual values that was assigned to to that object
will be lost.
How does your solution save the data ?
Thanks
Rog
 
J

Jan Tielens

The wrapper objects for the proxy objects transfer the changes to the
original proxy objects. So changes are persisted to the underlying objects.
You can retrieve the original array from the wrapped array so you could pass
it back to a web service for example.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top