Problem with dataKeyField

Discussion in 'ASP .Net Datagrid Control' started by Flare, Sep 26, 2004.

  1. Flare

    Flare Guest

    Hi

    Im having a problem with the DataKeyField and a array of a custom class.

    I have eg. this class

    class employee
    {
    public int ID
    { get / set }
    public String Name
    { get / set }
    }

    I can do this
    Employee emp[] = FACTORY.GetEmployees();
    datagrid1.DataSource = emp; // OK
    datagrid1.DataKeyField = "ID";

    The error is:
    Value cannot be null. Parameter name: container.

    What am I doing wrong and how do I solve it. The employee class is en
    reality an autogenerated O/R mapping class.

    Thanks in regards
    Anders
     
    Flare, Sep 26, 2004
    #1
    1. Advertising

  2. is your "ID" field the primary key in the database? it has to be for this to
    work

    --
    Regards,
    Alvin Bruney
    [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
    Got tidbits? Get it here... http://tinyurl.com/27cok
    "Flare" <> wrote in message
    news:%23z7fkG$...
    > Hi
    >
    > Im having a problem with the DataKeyField and a array of a custom class.
    >
    > I have eg. this class
    >
    > class employee
    > {
    > public int ID
    > { get / set }
    > public String Name
    > { get / set }
    > }
    >
    > I can do this
    > Employee emp[] = FACTORY.GetEmployees();
    > datagrid1.DataSource = emp; // OK
    > datagrid1.DataKeyField = "ID";
    >
    > The error is:
    > Value cannot be null. Parameter name: container.
    >
    > What am I doing wrong and how do I solve it. The employee class is en
    > reality an autogenerated O/R mapping class.
    >
    > Thanks in regards
    > Anders
    >
    >
     
    Alvin Bruney [MVP], Sep 28, 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. sramruttun
    Replies:
    0
    Views:
    353
    sramruttun
    Jul 10, 2003
  2. Felbrigg

    Composite DataKeyField?

    Felbrigg, Feb 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,864
    Ismail Rajput
    Feb 11, 2004
  3. Beryl Small

    DatakeyField with multi-column primary key

    Beryl Small, Mar 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    449
    Beryl Small
    Mar 1, 2004
  4. Homer J. Simpson
    Replies:
    2
    Views:
    1,128
    Suresh
    Mar 5, 2004
  5. Adam Knight

    DataGrid - DataKeyField!!

    Adam Knight, Aug 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    4,243
    Adam Knight
    Aug 7, 2005
Loading...

Share This Page