Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid DataKeyField and Webservice Proxy Objects

Reply
Thread Tools

Datagrid DataKeyField and Webservice Proxy Objects

 
 
Stephen Woolhead
Guest
Posts: n/a
 
      12-16-2004
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.


 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      12-19-2004
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
http://www.velocityreviews.com/forums/(E-Mail 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.
>
>
>.
>

 
Reply With Quote
 
 
 
 
Stephen Woolhead
Guest
Posts: n/a
 
      12-20-2004
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" <(E-Mail Removed)> wrote in message
news:129601c4e617$a6528a40$(E-Mail Removed)...
> 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 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.
>>
>>
>>.
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid - DataKeyField!! Adam Knight ASP .Net 0 08-07-2005 02:33 PM
How to get the DataKeyField in the DataGrid ? Kylin ASP .Net Datagrid Control 1 05-31-2005 04:56 AM
DataGrid's DataKeyField Value (C#) A. Atienza ASP .Net Datagrid Control 1 12-07-2004 08:23 AM
Newbie question: ASP Datagrid + Complex DataKeyField Homer J. Simpson ASP .Net 2 03-05-2004 06:34 PM
how to get datagrid item index from DataKeyField value? Sean ASP .Net Datagrid Control 1 08-07-2003 12:11 AM



Advertisments