Datagrid DataKeyField and Webservice Proxy Objects

S

Stephen Woolhead

Hi all, I have a web service that returns me an array of objects.

When I try to set this array as the datasource for a Datagrid and call
DataBind I get the following error message

DataBinder.Eval: 'MyWebService.SalesQuote' does not contain a property with
the name OurRef.

The code that causes the problem is:

'MyWebService.Exchequer ews = new Exchequer () ;
SalesQuote[] ds = ews.GetSalesQuotesForAccount (AccountCode) ;

dg.DataSource = ds ;
dg.DataKeyField = "OurRef" ; << Source of error
dg.DataBind () ; << Code goes bang here

The SalesQuote object does have a OurRef member, I can see it in the
debugger. The only thing I can think of is that the OurRef is a member
variable not a property. Would this stop the dataGrid binding?

The SalesQuote class is a proxy class generated via 'Add WebReference' ;

Thanks

Stephen.
 
E

Elton Wang

Hi Stephen,

Because you bind the datagrid to an array, it cannot map a
named field. So if you want to set datagrid's
DataKeyField, you have to bind data source to a DataTable.
Since you get data from a Web Service, it's better let the
web service has a method to return a DataSet as data
source.

Elton Wang
(e-mail address removed)
 
S

Stephen Woolhead

Thanks for the reply.

In the end I have taken a copy of the reference.cs file that the web service
genertated and modified so that the proxy objects use properties rather than
member fields. All seems to work fine now.

Stephen.

Elton Wang said:
Hi Stephen,

Because you bind the datagrid to an array, it cannot map a
named field. So if you want to set datagrid's
DataKeyField, you have to bind data source to a DataTable.
Since you get data from a Web Service, it's better let the
web service has a method to return a DataSet as data
source.

Elton Wang
(e-mail address removed)

-----Original Message-----
Hi all, I have a web service that returns me an array of objects.

When I try to set this array as the datasource for a Datagrid and call
DataBind I get the following error message

DataBinder.Eval: 'MyWebService.SalesQuote' does not contain a property with
the name OurRef.

The code that causes the problem is:

'MyWebService.Exchequer ews = new Exchequer () ;
SalesQuote[] ds = ews.GetSalesQuotesForAccount (AccountCode) ;

dg.DataSource = ds ;
dg.DataKeyField = "OurRef" ; << Source of error
dg.DataBind () ; << Code goes bang here

The SalesQuote object does have a OurRef member, I can see it in the
debugger. The only thing I can think of is that the OurRef is a member
variable not a property. Would this stop the dataGrid binding?

The SalesQuote class is a proxy class generated via 'Add WebReference' ;

Thanks

Stephen.


.
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top