Datagrid DataKeyField and Webservice Proxy Objects

Discussion in 'ASP .Net Datagrid Control' started by Stephen Woolhead, Dec 16, 2004.

  1. 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.
    Stephen Woolhead, Dec 16, 2004
    #1
    1. Advertising

  2. Stephen Woolhead

    Elton Wang Guest

    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



    >-----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.
    >
    >
    >.
    >
    Elton Wang, Dec 19, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:129601c4e617$a6528a40$...
    > 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
    >
    >
    >
    >>-----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.
    >>
    >>
    >>.
    >>
    Stephen Woolhead, Dec 20, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Homer J. Simpson
    Replies:
    2
    Views:
    1,104
    Suresh
    Mar 5, 2004
  2. Adam Knight

    DataGrid - DataKeyField!!

    Adam Knight, Aug 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    4,182
    Adam Knight
    Aug 7, 2005
  3. Sean

    how to get datagrid item index from DataKeyField value?

    Sean, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    755
    Arthur
    Aug 7, 2003
  4. A. Atienza

    DataGrid's DataKeyField Value (C#)

    A. Atienza, Dec 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    334
    Michael Tkachev
    Dec 7, 2004
  5. Kylin

    How to get the DataKeyField in the DataGrid ?

    Kylin, May 31, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    460
    Brock Allen
    May 31, 2005
Loading...

Share This Page