DataBinding to Array of Custom Objects

Discussion in 'ASP General' started by Jed, Nov 10, 2004.

  1. Jed

    Jed Guest

    I have a web service method that returns an array of custom objects marked
    serializeable with fully described public properties.

    When I bind the results to a DataGrid I can access the properties in the
    ItemDataBound event of the codebehind but I can't access them declaratively
    in the HTML code?

    Here is the code to call the method.
    net.mysite.www.WSInterface proxy;
    proxy = new net.mysite.www.WSInterface();
    ProjectList[] pl = proxy.getProjects("%",false,true);
    this.DataGrid1.DataSource = pl;
    this.DataGrid1.DataBind();

    Here is the code to access the property in the Item databound event.
    lbl.Text = ((ProjectList)dg.DataItem).ClientName;

    Here is the code that won't work on the HTML side:
    Option 1:
    <asp:BoundColumn HeaderText="Client Contact"
    DataField="ClientContact"></asp:BoundColumn>

    Option 2:
    <asp:TemplateColumn HeaderText="Contact">
    <ItemTemplate><%# DataBinder.Eval(Container.DataItem,
    "ClientContact")%></ItemTemplate>
    </asp:TemplateColumn>

    Here is the error:
    DataBinder.Eval: 'net.mysite.www.ProjectList' does not contain a property
    with the name ClientContact.

    Why can I access the property in the ItemDataBound event but not on the
    declarative side?

    The Page obviously know what kind of Object the data item is, otherwise the
    error could not report it.

    Any ideas? Thanks!
    Jed, Nov 10, 2004
    #1
    1. Advertising

  2. Jed wrote:
    > I have a web service method that returns an array of custom objects
    > marked serializeable with fully described public properties.
    >
    > When I bind the results to a DataGrid I can access the properties in


    There was no way for you to know it, but this is a classic asp newsgroup.
    While you may be lucky enough to find a dotnet-savvy person here who can
    answer your question, you can eliminate the luck factor by posting your
    question to a group where those dotnet-savvy people hang out. I suggest
    microsoft.public.dotnet.framework.adonet or
    microsoft.public.dotnet.framework.aspnet.

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
    Bob Barrows [MVP], Nov 10, 2004
    #2
    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. =?Utf-8?B?SW1hciBTcGFhbmphYXJz?=

    Databinding to custom properties of a custom class in ASP.NET 2

    =?Utf-8?B?SW1hciBTcGFhbmphYXJz?=, Apr 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    577
    =?Utf-8?B?SW1hciBTcGFhbmphYXJz?=
    Apr 20, 2005
  2. jobs
    Replies:
    0
    Views:
    1,591
  3. Earl Teigrob
    Replies:
    1
    Views:
    385
    Shravan
    Mar 1, 2004
  4. Dan Caron
    Replies:
    1
    Views:
    179
  5. Chris McKenzie

    Databinding to arrays of custom objects returned from a webservice

    Chris McKenzie, Apr 22, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    112
    Chris McKenzie
    Apr 22, 2004
Loading...

Share This Page